Interesting, sorry I missed this the first time. Derek's got it right, your best bet is to use Stupid Index Tricks.
I think the reason it doesn't exist is that the concept of indexing a high dimensional object across only a single dimension is not well formed. The closest thing I can think of is an index-finding collapse operator: i.e. one that considers your N-dimensional object as a collection of N-1 dimensional objects and collapses each N-1 object into a single bit (for indexing). Of course, when fed an M- dimensional array (with M>N) you probably want threading to occur -- ie to follow the usual threading idea and produce a collection of indices, considering the whole M-dimensional shebang as a collection of N-dimensional objects (which are themselves collections of N-1- dimensional things). The latter is in general difficult because the number of indices in a which-style index list usually isn't fixed across those higher thread dimensions, so you don't know what size to make the output. That's why whichND does what it does - producing a 1-D list of true locations in its source array, preserving all index dimensions so you can sort it out yourself. Anyhow, PDL does provide the tools to do what I think you want (producing indices into a collection of higher-dimensional objects): you just need to generate an appropriate collapse expression using the existing collapse operators, and index that with which or whichND. For example, to report (say) all columns of an RGB image (in (X,Y,color) order) that contain at least one pure green pixel, you could use: $col_dex = ( $rgb->mv(2,0) != 0 ) ^ (pdl(1,0,1)))->andover - >mv(1,0)->orover -> whichND; Here, the beginning stuff (up to and including the first "andover") finds pure green pixels (collapsing over the RGB axis to yield a 2-D object), the ->mv(1,0)->orover collapses over Y, leaving only a 1-D object, and the whichND indexes that. The expression isn't fully threadable (i.e. doesn't automagically do the Right Thing on arrays of RGB images stacked into a 4th or higher dimension), because indexing isn't an inherently vectorizable operation. But if you want to do something threaded, you can stack up all the columns found in the image set, and operate on those: $cols = $rgb->indexND($col_dex); # output is (<n>, Y, color) Er, I hope that all make sense... On Mar 9, 2011, at 10:14 AM, Derek Lamb wrote: > On Mar 9, 2011, at 7:33 AM, Ivan Shmakov wrote: > >> FWIW, it was the ->dice_axis () method that I was searching for. >> >> However, it makes me wonder, why there isn't a method, let me >> call it ->where_axis (), which relates to ->where () roughly as >> ->dice_axis () relates to ->dice ()? IOW, a ->where () limited >> to a single dimension? > > probably because nobody has written it yet! You can probably figure > out how to cook up whatever you need with a judicious use of > dummy(). For example: > > $a = sequence(10,4); > $m1 = sequence(4) % 2; > $m2 = sequence(10) % 3; > print $a->where($m1->dummy(0,10)); > print $b->where($m2->dummy(1,4)); > > Derek > > >> >> -- >> FSF associate member #7257 >> _______________________________________________ >> 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 > _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
