Hi folks,

I'm using PDL (the Perl Data Language, pdl.perl.org) to manipulate a Very Large dataset.

I'm having quite a bit of trouble with the correct syntax for threading, can't seem to get it right.

Right now I'm doing a lookup, where an old value gets turned into a new value. There's a one-to-one relationship between old values and new values. Currently I'm doing this using a normal hash, like this:

my @old_values = list($pdl_oldvalues); my @new_values = map $hash_lookup->{$_}, @old_values; my $pdl_newvalues = pdl(\@new_values);

I'd like to do this using PDL threading if I can, because I want it to go quicker (there are a lot of values), but I can't find the right way to do it.

I've tried:

my $pdl_newvals = $hash_lookup->{$pdl_oldvals};
but sadly that doesn't work. I've tried using $pdl_oldvals->thread(0) and $pdl_oldvals->dummy(0) but they don't work either.

I've also tried turning the hash into a two-row pdl, with keys on one row and values on the other row, then taking a slice from that pdl to get the values. That should certainly work with pdl threading... but I can't get it to. :(

Suggestions, and examples of correct syntax for doing this kind of thing in pdl, very much appreciated.

All the best, andye.

PS where "doesn't work" = either a syntax error, or runs but produces the wrong values...


In reply to Hash-type lookup in PDL by andye

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.