Nice. That stringification is pretty expensive just to test for emptiness - you could also use ->nelem to test for zero elements.
(Mobile) > On Sep 26, 2014, at 3:11 PM, Judy Hawkins <jlhark...@yahoo.com> wrote: > > This is my howto file for comparing pdls: > > use Test::More 'no_plan'; > > use PDL; > use PDL::NiceSlice; > use PDL::IO::SndFile; > > my $a = pdl(2,3,4); > my $b = pdl(2,3,4); > > my $cmp = which($a - $b); > ok (($cmp =~ m/Empty/), 'the two pdls match'); > > > my $e = pdl(3,4,5); > $cmp = which($a - $e); > ok (not ($cmp =~ m/Empty/), 'the two pdls do not match'); > print "$cmp\n"; > my $them = pdl(0,1,2); > my $cmpcmp = which($cmp - $them); > ok (($cmpcmp =~ m/Empty/), 'all three did not compare'); > > > $c = pdl(2,3,10); > $cmp = which($a - $c); > print "$cmp\n"; > $them = pdl(2); > $cmpcmp = which($cmp - $them); > ok (($cmpcmp =~ m/Empty/), 'just the third did not compare'); > > > Hope that helps! > > Judy > > > On Friday, September 26, 2014 2:30 PM, Vikas N Kumar <vi...@cpan.org> wrote: > > > Hi > > I am stumped by the problems I face with simple conditionals in using > the which() function. I have tried many different ways in trying to > solve it but none of them give me the result I want. > > Here is a sample: > > use PDL; > # a random list of values that are above and below 0 > my $a = randsym(100) - 0.5; > > # create a lag of 1 > my $idx = xvals($a->dims) - 1; > $i = $i->setbadif($i < 0)->setbadtoval(0); # can this be more elegant ? > > # find all the positions where $a[i] > 0 and $a[i - 1] < 0 > # in essence where $a crosses the zero line > my $b = zeroes($a->dims); > my $b_idx = which($a > 0 && $a->index($i) < 0); > > # set those points as 1 > $b->index($b_idx) .= 1; > > Everytime I run this I get "multielement piddle in conditional > expression" errors. > > I have not been able to find an elegant solution to this problem. I > cannot seem to create a mask that has more than 1 piddle comparisons. > > Please help. > > Thanks > Vikas > > > _______________________________________________ > Perldl mailing list > Perldl@jach.hawaii.edu > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > > > _______________________________________________ > Perldl mailing list > Perldl@jach.hawaii.edu > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
_______________________________________________ Perldl mailing list Perldl@jach.hawaii.edu http://mailman.jach.hawaii.edu/mailman/listinfo/perldl