Thank you for the additions! One question - why do you have the comment of '?' for 'use strict' - is that bad practice?
Matt On Thu, May 13, 2010 at 7:46 AM, David Mertens <[email protected]> wrote: > If you want the syntax to be in line with where's syntax, you could pop $w > off at the beginning and then apply the same routine to each element in @_. > I've modified your function (untested) to give you an idea of what I mean: > > sub whereND { > use strict; # ? > # w is a mask 0 = false, 1 = true > my $w = pop @_; > my @to_return; > foreach my $i (@_) { > # 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); > > push (@to_return, $i->indexND($t)); > } > > return @to_return; > } > > David > -- 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
