In addition to Jarle's cc8compt example, you could also use run-length 
encoding to pull out all the beginnings and ends. The pdl(0)->append at 
the beginning and the $begs-1 and $ends-1 at the end are necessary 
because otherwise a series of non-zeroes at the start won't get counted 
correctly:

sub splitit2{
    my $in = pdl(0)->append(shift);

    my ($num,$vals)=rle($in);
    my $cumusum = cumusumover($num);
    my $ends = $cumusum->where($vals)-1;
    my $begs = $cumusum(which($vals)-1);
    return ($begs-1,$ends-1);
}

cheers,
Derek


Martin A. Hansen wrote:
> Hello,
>
>
> I have a 1D piddle [0,0,1,1,1,0,0,0,0,1,1,1,1,0,0]
>
> and would like to scan the piddle for the next interval of non-zero 
> values given an offset:
>
> ( beg, end ) = scan( pdl, 0 ); # return beg=2, end=4
> ( beg, end ) = scan( pdl, 5 ); # return beg=9, end=12
>
>
> How do you do that with PDL ?
>
>
>
> Martin
> ------------------------------------------------------------------------
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>   


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

Reply via email to