Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How to shift the columns of a PDL matrix

by Anonymous Monk
on Jul 03, 2007 at 20:42 UTC ( [id://624781]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a PDL that is 8 columns by 120 rows.

I want to simply SHIFT all the columns to the right by 1 and insert a column of 0's for the first column. I would prefer to DROP the last column so I don't change the dimensions.

I think I can do it by slicing and gluing into a new PDL, but was wondering if there was any faster function that would hel me do it. I would prefer to use "inplace" if possible to minimize memory.

Also, I am aware of the SHIFTRIGHT function, but that doesn't seem to be doing the job. I believe that is a binary shift function.

Thanks!

  • Comment on How to shift the columns of a PDL matrix

Replies are listed 'Best First'.
Re: How to shift the columns of a PDL matrix
by lin0 (Curate) on Jul 03, 2007 at 22:35 UTC

    Hi Anonymous Monk,

    you could use something like:

    $pdl = append(zeroes(1,$pdl->getdim(1)), $pdl(0:-2,:));

    where $pdl is your 8 columns by 120 rows piddle

    Note: I am assuming you are using PDL::NiceSlice

    Cheers,

    lin0

      since you don't want to grow your matrix, it is even simpler to use rotate to shift your columns and then insert your new data.

      $pdl=$pdl->rotate(1); $pdl(0,).=$new_data # your vector.

Log In?
Username:
Password:

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

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

    No recent polls found