Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Can't figure out simple transformation with PDL

by fglock (Vicar)
on Mar 19, 2013 at 09:17 UTC ( [id://1024243]=note: print w/replies, xml ) Need Help??


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] ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1024243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-20 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found