Thanks for the hints - I think that this is now a fully working whereND code:

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 $mask = $w * ones($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)};

    # calculate the indicies of $mask
    my $t = whichND($mask);

    # reshape $t so that it will look into $i correctly
    $t->reshape($mask->ndims, $n, @idims);

    return ($i->indexND($t));
}



-- 
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