Nice, Derek! Good catch (it is pretty cool to see how powerful a few lines of PDL can be).
--Chris On Fri, Oct 17, 2014 at 3:19 PM, Derek Lamb <[email protected]> wrote: > Ronak, > > If you are looking for the smallest 3 unique values, and those are "d", > "e", and "f", do you want all of the locations where your piddle is "d" or > "e" or "f" ? Or if "d" is the smallest, just 3 "d" locations? If the > latter, then what Chris has will work as-is. If the former, then you need > a little bit extra at the beginning: > > $matrix = pdl([0,1,2,3,4],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8]); > $k = 3; > ($quant,$uniq_vals)=$matrix->flat->qsort->rle; #I am a big fan of > ->qsort->rle. ->hist() might work too. > $num_in_matrix = $quant(0:$k-1)->sum; > #then Chris's stuff will work > $smallest_k = zeroes(indx, $num_in_matrix); > $matrix->flat->minimum_n_ind($smallest_k); #answer gets stuffed into > $smallest_k > $coords2D = pdl($matrix->one2nd($smallest_k)); > $smallest_vals = $matrix->range($coords2D->transpose)->flat; > > cheers, > Derek > > On Oct 17, 2014, at 10:29 AM, Chris Marshall <[email protected]> > wrote: > > Hi- > > First off, you can use the PDL on-line documentation to > find relevant commands to try: > > pdldoc -a maximum > > or > > pdl> apropos maximum > > in the pdl2 or perldl shells includes the following items: > > maximum Project via maximum to N-1 dimensions > maximum_ind Like maximum but returns the index rather than the > value > maximum_n_ind Returns the index of `m' maximum elements > > where maximum_n_ind is what you are looking for. Here is a > sample pdl2 session showing the calculation. You can use > the PDL shells and the online documentation to understand > fully how it works: > > > pdl> floor(random(10,10)*10) >> pdl> p $m >> [ >> [4 7 5 0 6 7 8 4 6 7] >> [0 7 0 2 5 3 0 4 6 6] >> [5 4 3 6 9 5 8 4 4 1] >> [9 6 7 7 4 1 4 2 0 8] >> [5 1 3 3 7 7 1 2 8 5] >> [2 0 8 7 3 1 5 7 7 6] >> [5 9 6 2 7 2 6 7 0 2] >> [6 3 1 1 8 2 1 9 9 9] >> [6 7 9 3 5 2 2 5 9 3] >> [4 5 0 4 7 9 3 3 1 6] >> ] >> >> pdl> $top5 = zeros indx, 5; # size of $top5 determines n >> pdl> $m->flat->maximum_n_ind($top5) # get top 5 element indexes >> pdl> p pdl($m->one2nd($top5)) # convert linear to ND index >> [ >> [4 0 1 7 8] >> [2 3 6 7 7] >> ] >> >> >> > Hope this helps, > Chris > > > On Fri, Oct 17, 2014 at 11:54 AM, Ronak Agrawal <[email protected]> > wrote: > >> First I would Thank You for your constant help...it has helped me a lot >> in improving my skills >> ------- >> >> I have generated a Hankel Matrix by the following operation >> >> // $a is a svd and therby this operation will always form Hankel Matrix >> $matrix = $a x transpose($a); >> >> [image: [a b c d e; b c d e f; c d e f g; d e f g h; e f g h i].] >> >> I need to find the top K minimum elements ( 2D) with their 2 Dimesional >> indices .. >> Can you suggest me some good approach for this >> >> I though to do following but it is not optimized >> Converting the Lower triangular Matrix as Bad Values or 0 >> Then Finding the mimimum row_wise and column_wise using minimum function >> >> Thanks >> >> >> >> >> >> _______________________________________________ >> 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 > >
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
