mxb has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I am currently learning PDL and I've come up against a situation for which I cannot figure out how to proceed. I have a 2D array, comprised of multiple 1D byte vectors which may or may not be unique. I wish to count the number of unique vectors within the array - essentially a histogram of vector counts. My data is too big for here, but the following example demonstrates the issue I am having.
pdl> p $x [ [0 1 2] [3 4 5] [6 7 8] [0 1 2] [0 1 2] [6 7 8] ]
I know I can retrieve a list of unique elements:
pdl> p uniq $x [0 1 2 3 4 5 6 7 8]
I know I can retrieve a histogram of all elements:
pdl> p scalar hist $x,0,256,1 [3 3 3 1 1 1 2 2 2 0 0 0 0 0 ....]
What I would like is something like the following output:
I think my issue stems from the fact that PDL is designed for operations on PDL elements. I am currently contemplating if the best solution to my problem is to have a lookup table of the data I am putting in vectors to an index, for example:[0 1 2] 3 [3 4 5] 1 [6 7 8] 2
my %lookup = ( 0 => "0 1 2", 1 => "3 4 5", 2 => "6 7 8", ); # Then $x reduces down to $x = [ 0 1 2 0 0 2 ];
Any advice would be welcome, as both PDL and numerical computing are new to me, thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Counting PDL vectors in a PDL matrix
by choroba (Cardinal) on Feb 20, 2018 at 11:02 UTC | |
Re: Counting PDL vectors in a PDL matrix
by vr (Curate) on Feb 20, 2018 at 19:30 UTC | |
by mxb (Pilgrim) on Feb 21, 2018 at 15:25 UTC | |
by etj (Priest) on May 07, 2022 at 23:08 UTC | |
Re: Counting PDL vectors in a PDL matrix
by corenth (Monk) on Feb 20, 2018 at 17:08 UTC |