I used dice_axis to swap rows, could use this with a combination with xchg to
do it for any dimension.
pdl> p $a=sequence(10,4)
[
[ 0 1 2 3 4 5 6 7 8 9]
[10 11 12 13 14 15 16 17 18 19]
[20 21 22 23 24 25 26 27 28 29]
[30 31 32 33 34 35 36 37 38 39]
]
pdl>p $idx=pdl(0,3,2,1)# create the desired row sequence
[0 3 2 1]
pdl> p $t=$a->dice_axis(1,$idx)
[
[ 0 1 2 3 4 5 6 7 8 9]
[30 31 32 33 34 35 36 37 38 39]
[20 21 22 23 24 25 26 27 28 29]
[10 11 12 13 14 15 16 17 18 19]
]
Would this not do it pretty easily?
CLIFF SOBCHUK
Core RF Engineering
Phone 613-667-1974 ecn: 8109-71974
mobile 403-819-9233
yahoo: sobchuk
www.ericsson.com
"The author works for Telefonaktiebolaget L M Ericsson ("Ericsson"), who is
solely responsible for this email and its contents. All inquiries regarding
this email should be addressed to Ericsson. The web site for Ericsson is
www.ericsson.com."
This Communication is Confidential. We only send and receive email on the basis
of the terms set out at www.ericsson.com/email_disclaimer
-----Original Message-----
From: David Mertens [mailto:[email protected]]
Sent: July-27-11 3:02 PM
To: perldl
Subject: [Perldl] Exchanging rows in a matrix
Hey folks -
I've been on PerlMonks today and found somebody playing with matrices.
Somebody asked why they didn't use PDL and BrowserUK (not the OP) responded
with this:
--------%<--------
I think that if an algorithm requires access to individual elements of the
piddles, rather than being able to apply single operations to whole piddles at
a time, there is little to be gained. What you might gain from more efficient
duplication, you lose by having to call one or two functions per element during
calculation or conditional testing.
>From my very limited understanding of the OPs problem, much of the effort
>involved in the algorithm involves:
* interchanging whole rows & whole columns in 2D arrays.
I don't think that PDL is particularly efficient at performing these
operations, especially the latter.
* performing "bit-wise" boolean operations and
'counting-the-set-bits', on pairs of rows of zeros and ones.
If the rows of 0s and 1s were encoded as simple bit-vectors, then not only
can standard Perl can perform both these operations more efficiently than PDL,
the storage requirements are 8x less.
I'd be very happy to be wrong here, but I just don't think PDL suits these
particular types of operations.
-------->%--------
I responded saying that the second operation is easy, but I found the first
operation to be surprisingly difficult. BrowserUK's query and my response are
viewable here: http://www.perlmonks.org/?node_id=917089;
the original discussion is this thread:
http://www.perlmonks.org/?node_id=916850
If anybody who is more familiar with row and column exchanges to could clear
this up, I'd greatly appreciate it.
David
--
Sent via my carrier pigeon.
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl