in reply to Re^2: PDL threading where/which instead of loop
in thread PDL threading where/which instead of loop

Here is one way to achieve this without constructing a loop that iterates over each element of the pdl. I'm not sure that this would be significantly faster than just iterating over the elements of the pdl...you would need to benchmark it (also you may want to consider comparing it to a plain-perl solution).
#!/usr/bin/env perl use strict; use warnings; use PDL; use PDL::NiceSlice; my $dec = pdl [[1,1,2,2,3],[10,15,13,11,6]]; my $groups_vec = $dec(:,0); my $groups = $groups_vec->uniq; my $groups_t = $groups->transpose; my $values = $dec(:,1); my $masks = ($groups_t == $groups_vec); my $group_values = $masks*$values; my $max_of_each_group = $group_values->maximum; my $final_pdl = pdl($groups, $max_of_each_group)->transpose; print "Original Data: $dec\n"; print "Groups: $groups\n"; print "Transposed Groups: $groups_t\n"; print "Masks: $masks\n"; print "Group values: $group_values\n"; print "Max of each group: $max_of_each_group\n"; print "Final pdl: $final_pdl\n"; exit;
Gives the following output:
Original Data: [ [ 1 1 2 2 3] [10 15 13 11 6] ] Groups: [1 2 3] Transposed Groups: [ [1] [2] [3] ] Masks: [ [1 1 0 0 0] [0 0 1 1 0] [0 0 0 0 1] ] Group values: [ [10 15 0 0 0] [ 0 0 13 11 0] [ 0 0 0 0 6] ] Max of each group: [15 13 6] Final pdl: [ [ 1 15] [ 2 13] [ 3 6] ]