Hello,

I am working with PDL's for a project and have a question involving ranges of consecutive values, and generating a piddle based on the indexes there.

I have a PDL with 3 rows which correlate with each other. The first row is my values, the second is the time at which those values took place, and the third is a mask of 0's and 1's. For the purposes of what I'm doing, we can ignore the GMT row.

Here's a visual of what I'm working with:
$value = [1, 20, 60, 3, 900, 34, 93, 5, 12, 24, 16, 200] $mask = [ 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 ]
As you can see, each pdl has 12 elements. What I need to do is take and create a new PDL of the elements in $value that have consecutive 0's in $mask. I also need to preserve their indexes within $values. As an example using the above, the output I desire is a piddle like this:
$a1 = [ [60,30,900] #from $values [2,3,4] #their original indexes ] and $a2 = [ [5,12,24] [7,8,9] ]
(Where the above is a pdl with 2 pdls inside)

These would be generated from the consecutive 0's which occur in the mask.

I hope that my wording is clear and illustrates my point properly. Any and all help on this would be appreciated, as there may be some PDL function that I am unaware of that would aid me here.

Thanks

In reply to Working with PDL, need index range of consecutive values by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.