use warnings; use strict; use PDL; use PDL::NiceSlice; use Test::PDL 'eq_pdl', -tolerance => 0.42; my $mask = zeroes 7,7,3; $mask( pdl( 0..2, 4..6 ), 4, 0:2 ) .= 1; $mask( 4, pdl( 0..2, 4..6 ), 0:2 ) .= 1; my $good_matrix = random 7,7,3; my $some_matrix; my $count; while () { $some_matrix = random 7,7,3; last if eq_pdl $good_matrix * $mask, $some_matrix * $mask; $count ++ } $PDL::doubleformat = '%.1f'; print "it worked only after $count attempts,\n", "mask was: $mask", "good matrix was: $good_matrix", "and it was not very different from: $some_matrix";