in reply to Re: Hash-type lookup in PDL
in thread Hash-type lookup in PDL
That gives this output:#!/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";
I would be a happy bunny if it gave this output:[0 1 2 3 4] [0 0 0 0 0]
Best wishes, andye[0 1 2 3 4] [101 69 42 10042 99]
(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:
but that has two problems:my $pdl_table = pdl([keys %$lookup], [values %$lookup]); my $y = zeroes(5); $y .= $pdl_table->(which($pdl_table->(:,0) == $x),1 +); print "$y \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Hash-type lookup in PDL
by lin0 (Curate) on Jan 05, 2007 at 19:52 UTC | |
by andye (Curate) on Jan 06, 2007 at 18:17 UTC |