use warnings; use strict; use PDL; use PDL::NiceSlice; #fancy matrix #set to a blank 3d test matrix my $matrix = zeroes 7,7,3; #set some values for matrix $matrix( pdl( 0..2, 4..6 ), 4, 0:2 ) .= 1; $matrix( 4, pdl( 0..2, 4..6 ), 0:2 ) .= 1; #the conditional problem child my $ind = $matrix-> whichND( $matrix == 1 ); if ( all $matrix-> indexND( $ind ) == 1 ) { print "it worked\n"; }