HI-

I am new to PerlDL.  I've attempted to read all the documentation I can 
but I have yet to find a solution to my question.

Say I have a 1-D piddle that looks like:
[1 2 3 2 1 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0]

I can use which_both to determine the index of the non-zero and zero 
positions like so:
non_zero = [0 1 2 3 4 10 11 12 13 14 15 16]
zero = [5 6 7 8 9 17 18 19]

What I really want is the number of consecutive zeros.  In other words 
the length of the zero "gaps" in signal.  I could iterate over each zero 
index position and do some math (ie. (9-5+1) = 5); however, this is 
terribly inefficient and I'll be performing this calculation millions of 
times.

Please let me know if any additional information would help.  Example 
code below.

Thanks,
Jason


use PDL;

my @array = qw/1 2 3 2 1 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0/;
my $p = pdl @array;
my ($non_zero_idx, $zero_idx) = which_both($p);

print $p ."\n";
print $non_zero_idx ."\n";
print $zero_idx ."\n";
exit;

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

Reply via email to