Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Hash-type lookup in PDL

by lin0 (Curate)
on Jan 05, 2007 at 19:52 UTC ( [id://593197]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hash-type lookup in PDL
in thread Hash-type lookup in PDL

Hi andye,

If your lookup table is rather small, you could try this code:

#!/usr/bin/perl use warnings; use strict; use PDL; my $x = sequence(5); print "$x \n"; my @pdl_keys = (0, 1, 2, 3, 4); my @pdl_values = (101, 69, 42, 10042, 99); my $y = zeroes(5); foreach my $i (0..@pdl_keys-1){ my $indx = which($x == $pdl_keys[$i]); $y->dice($indx) .= $pdl_values[$i]; } print "$y \n";

I hope this helps

Cheers,

lin0

Replies are listed 'Best First'.
Re^4: Hash-type lookup in PDL
by andye (Curate) on Jan 06, 2007 at 18:17 UTC
    Many thanks zentara and lin0,

    Well, I went ahead and did it with my original approach of: convert the pdl to a perl list, then use a perl hash to look it up, then convert it back again. The batch job finished about half a day later, so it's an academic issue now really.

    Still, (as a note for for posterity) there seem really to be two options being discussed here:

    Either:

    - a PDL lookup table, using which() or dice() to look up one value at a time (slow on big datasets),

    or

    - convert all the values in advance, as per zentara's code above...

    Neither's ideal really... could be that converting to a perl scalar and using a hash is actually the best thing.

    Thanks for your help, and best wishes,
    andye

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593197]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found