Hi zentara, It's nothing complicated I'm looking to do, really, just lookup each value in a hash. Here's an example that doesn't work:
#!/usr/bin/perl use warnings; use strict; use PDL; my $x = sequence(5); print "$x \n"; my $lookup = { 0 => 101, 1 => 69, 2 => 42, 3 => 10042, 4 => 99 }; my $y = zeroes(5); $y .= $lookup->{$x}; print "$y \n";
That gives this output:
[0 1 2 3 4] [0 0 0 0 0]
I would be a happy bunny if it gave this output:
[0 1 2 3 4] [101 69 42 10042 99]
Best wishes, andye

(I tried using a straightforward my $y = $lookup->{$x} but that doesn't produce any value at all)

update: I've tried creating a pdl to use insread of the hash, like this:

my $pdl_table = pdl([keys %$lookup], [values %$lookup]); my $y = zeroes(5); $y .= $pdl_table->(which($pdl_table->(:,0) == $x),1 +); print "$y \n";
but that has two problems: Looks like I've screwed up the syntax in the which() statement, and I can't work out how to make it right - a dummy dimension somewhere?

In reply to Re^2: Hash-type lookup in PDL by andye
in thread 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.