http://qs321.pair.com?node_id=1024243


in reply to Can't figure out simple transformation with PDL

I'm starting with your original statements, and then setting the selected elements to '-1' here:

perldl> p $b = pdl (10..25)->reshape(4,4); [ [10 11 12 13] [14 15 16 17] [18 19 20 21] [22 23 24 25] ] perldl> p $pos = whichND($b == 21); [ [3 2] ] perldl> $xfrm = pdl [-1,0],[0,-1],[1,0],[0,1]; perldl> p $around = $b->indexND($pos + $xfrm, 'truncate'); [20 17 0 25] perldl> p $odd = $around->where( $around % 2 ); [17 25] perldl> $odd .= -1; # set original matrix through dataflow perldl> p $b [ [10 11 12 13] [14 15 16 -1] # odd elements around 21 are set to -1 [18 19 20 21] [22 23 24 -1] ]