Hello astroman,

I took some ideas from your reply to djerius to create this solution. I think this will work for you, and it keeps all the operations in piddles/PDL. Basically, I create masks for your greater than and less than or equal to conditions and apply them to "expanded" versions of your $a and $b piddles.

#!/usr/bin/env perl use strict; use warnings; use PDL; # The number of intervals you require (your example shows 3) my $n = 3; my $a = pdl (0,6,18,7,19,3,10,2,12,4,8,9,1,15,11,11,19,17,0,9); my $b = pdl (0,1,2,3,4,5,6,7,8,9,10,10.5,11,11.5,12,12.5,13,13.5,14,14 +.5); my $gt = sequence($n)*5; # equivalent to pdl(0, 5, 10) for $n = 3 my $ltoe = (sequence($n)+1)*5; # equivalent to pdl(5, 10, 15) for $n = + 3 my $expanded_a = $a->dummy(0,$n); my $expanded_b = $b->dummy(0,$n); my $gt_mask = $expanded_b > $gt; my $ltoe_mask = $expanded_b <= $ltoe; my $mask = $gt_mask & $ltoe_mask; my $mask_w_bad = $mask->setbadif($mask == 0); my $masked = $expanded_a * $mask_w_bad; my $medians = $masked->transpose->medover; print $medians, "\n"; exit;

In reply to Re: Grouping one piddle based on ranges of another by kevbot
in thread Grouping one piddle based on ranges of another by astroman

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.