I've written a version of whereND that does 'the right thing' in
threading a mask over higher dimensions of an input piddle, and it
returns a sensible looking piddle back.

The trouble is that the reshape() breaks the threading back to the
original piddle. Can any other pdlers suggest a way to return back a
piddle with dataflow all the way back to $i?

Thanks,

Matt

sub whereND {
    use strict;
    my ($i, $w) = @_;

    # w is a mask 0 = false, 1 = true
    # i is M dimensional
    # w is N < M dimensional
    # dims(i) 1..N == dims(i) 1..N
    # thread over N+1 to M dimensions

    my $n = sum($w);

    my $sub_i = $w * ones($i);

    my $where_sub_i = $i->where($sub_i);

    # count the number of dims in w and i
    # w = a b c d e f.....
    my @idims = dims($i);
    # ...and pop off the number of dims in w
    foreach(dims($w)){shift(@idims)};

    $where_sub_i->reshape($n, @idims);
    return ($where_sub_i);
}



-- 
Matthew Kenworthy / Assistant Professor / Leiden Observatory
Niels Bohrweg 2 (#463) / P.O. Box 9513 / 2300 RA Leiden / NL

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to