Oops, sorry, I miscounted the size of your output. (I am using my
phone on an island in the outer Hebrides and cannot currently run PDL!)
You can either specify a boundary condition for range (eg with a 't'
as the third argument) or reduce the size to 6x2 (the 7x2 is running
off the end of the input array.)
Best
Craig
On Sep 9, 2008, at 3:32 PM, Bruno Picard <[EMAIL PROTECTED]> wrote:
Hello Craig,
I cannot try your examples: do you use the same $x?
the error line says
index out-of-bounds in range at
Bruno.
Craig DeForest a écrit :
Hello, Bruno,
It is not quite clear what you are after. Range will preserve the
shape of the index variable, so if you use something other than
whichND to create it, you can make a 2-D result. You can also tell
range to pull out stacked subfields, one per index. These may be
helpful; in each case $out gets the same subfield as your example.
The first pulls a single 7-element subfield for each of two
locations (and transposes the 2x7 output to get your 7x2 result);
the second uses a dummy dimension to assemble a 2x7x2 index
variable, then collapses it by index into $x to get a 7x2 output.
$idx= pdl([4,0],[1,1]);
$out=$x->range($idx,[7,0])->xchg(0,1);
$idx= pdl([4,0],[1,1])->(:,*1) + yvals(7)*(xvals(2)==0);
$out = $idx->range($idx);
On Sep 9, 2008, at 1:07 PM, Bruno Picard <[EMAIL PROTECTED]> wrote:
Hi all,
Is there a smarter way to extract a 2D subset of a 2D matrix than
in the following example?
The problem is that I have to know the number of lines and cols of
the subset for the reshape....
perldl> $x = sequence(10,2)
perldl> p $x
[
[ 0 1 2 3 4 5 6 7 8 9]
[10 11 12 13 14 15 16 17 18 19]
]
perldl> $ind = whichND(($x>3) & ($x<18))
perldl> p $ind
[
[4 0]
[5 0]
[6 0]
[7 0]
[8 0]
[9 0]
[0 1]
[1 1]
[2 1]
[3 1]
[4 1]
[5 1]
[6 1]
[7 1]
]
perldl> $y = $x->range($ind)->reshape(7,2)
perldl> p $y
[
[ 4 5 6 7 8 9 10]
[11 12 13 14 15 16 17]
]
Cheers,
Bruno
--
____________________________________________________
Dr. Bruno Picard
CLS
Dir. Océanographie Spatiale, Dép. Traitement de la Mesure et Seg
ment Sol
Space Oceanography Division, Data Analysis and Ground Processing
Unit
8-10 rue Hermès, 31520 Ramonville Saint Agne, France
Tél: (+33)5.61.39.37.37 Fax: (+33)5.61.39.37.82
[EMAIL PROTECTED] http://www.cls.fr
http://www.jason.oceanobs.com (aviso site)
http://
www.ipcc.ch____________________________________________________
<mime-attachment.gif>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
Cliquez ici si ce message est indésirable (pourriel).
--
____________________________________________________
Dr. Bruno Picard
CLS
Dir. Océanographie Spatiale, Dép. Traitement de la Mesure et Segment
Sol
Space Oceanography Division, Data Analysis and Ground Processing Unit
8-10 rue Hermès, 31520 Ramonville Saint Agne, France
Tél: (+33)5.61.39.37.37 Fax: (+33)5.61.39.37.82
[EMAIL PROTECTED] http://www.cls.fr
http://www.jason.oceanobs.com (aviso site)
http://www.ipcc.ch____________________________________________________
<kodama.gif>
_______________________________________________
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