use strict; use warnings; use feature 'say'; use PDL; my $x = pdl [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 1, 2], [0, 1, 2], [6, 7, 8], ]; my @index; my @keys; my %count; for ( 0 .. $x-> dim( 1 ) - 1 ) { my $ref = $x-> slice( [], $_ )-> get_dataref; next if $count{ $$ref } ++; push @index, $_; push @keys, $$ref; } my $uniq = $x-> dice( 'X', pdl \@index ); my $counts = pdl @count{ @keys }; say $uniq; say $counts; say $uniq-> append( $counts-> transpose ); #### >perl pdl180220.pl [ [0 1 2] [3 4 5] [6 7 8] ] [3 1 2] [ [0 1 2 3] [3 4 5 1] [6 7 8 2] ]