On Sat, May 29, 2010 at 10:07 AM, Chris Marshall <[email protected]> wrote:

> It looks like you have #Var #Day-by-#Cell arrays, e.g.:
>
>   PDL> $var1 = pdl q[ 111 121 131 ; 211 221 231 ]
>   PDL> $var2 = pdl q[ 112 122 132 ; 212 222 232 ]
>   PDL> $var3 = pdl q[ 113 123 133 ; 213 223 233 ]
>   PDL> $var4 = pdl q[ 114 124 134 ; 214 224 234 ]
>
> so in this case V=#Var=4, D=#Day=3, C=#Cell=2 and you
> have 4 3x2 $varN arrays.  Ignoring the added index,
> the aggregate data array is VxDxC which you can get
> with cat:
>
>  PDL> $VAR= cat($var1,$var2,$var3,$var4)->mv(-1,0)
>  PDL> help 'vars'
>  PDL variables in package main::
>
>  Name         Type   Dimension       Flow  State          Mem
>  ----------------------------------------------------------------
>  $VAR         Double D [4,3,2]              -C           0.00Kb
>  $var1        Double D [3,2]                P            0.05Kb
>  $var2        Double D [3,2]                P            0.05Kb
>  $var3        Double D [3,2]                P            0.05Kb
>  $var4        Double D [3,2]                P            0.05Kb
>
>  PDL> p $VAR
>
>  [
>   [
>    [111 112 113 114]
>    [121 122 123 124]
>    [131 132 133 134]
>   ]
>   [
>    [211 212 213 214]
>    [221 222 223 224]
>    [231 232 233 234]
>   ]
>  ]
>
> To access the values for $day and $cell, you can slice as
> $VAR(:,($day-1),($cell-1)) where the -1 is because you have
> to convert between 1 offset counting and 0 offset counting
> as used by PDL, Perl, and C.
>
> Cheers,
> Chris
>
> On 5/29/2010 10:33 AM, P Kishor wrote:
> > I have the several piddles that look like so (actually, I have seven
> > or eight such piddles)
> >
> > $var1 = [
> > # day1 day2 day3 .. day365/366
> >   [111  121  131 ..]  # cell1
> >   [211  221  231 ..]  # cell2
> >   ..                         # a few hundred to 10s of 1000s cells
> > ]
> >
> > $var2 = [
> > # day1 day2 day3
> >   [112  122  132 ..]  # cell1
> >   [212  222  232 ..]  # cell2
> >   ..
> > ]
> >
> > I want to create the following composite piddle
> >
> > $vc = [
> > # cell day var1 var2 .. var7
> >   [   1     1      111    112 ..]
> >   [   1     2      121    122 ..] #<<<
> >   [   1     3      131    132 ..]
> >   ..
> >   [   1  365  13651 13652 ..]
> > # end of cell1
> >   [   2     1      211     212 ..]
> >   [   2     2      221     222 ..]
> >   [   2     3      231     232 ..]
> > ..
> >   [   2  365  23651 23652 ..]
> > # end of cell2
> > ]
> >
> > and then, I want to be able to get all the values for any given cell
> > and day combination. So, for cell = 1, day = 2, I want the row marked
> > with #<<<  above.
> >
> > 1 2 121 122 ..
> >
> > My hope is to do something like so
> >
> > for my $cell (1 .. $ncells) {
> >     for my $day (1 .. $ndays) {
> >         do something with $cell, $day, $var1, $var2 ..
> >         where $var1, $var2, etc. are for the specific $cell, $day combo
> >
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>

So Chris's point was that you could simply use one of the indices to keep
track of your day and cell. What's more, you can probably write a nice
Inline::Pdlpp function to handle your 'do something with data' that you
mention in your original post. It might be a bit confusing if you've never
played around with PDL::PP before, but here's a prototype for how that might
look, to get you going. You can find more info on Inline::Pdlpp at
http://search.cpan.org/~chm/PDL-2.4.6/Basic/Gen/Inline/Pdlpp.pm, and you can
find more info on PDL::PP at http://pdl.perl.org/?docs=PP&title=PDL::PP. I
wish the docs were bit more beginner-friendly, but it's not my top priority
at the moment. Still, ask questions if you've got them and we'll be happy to
help.

-------------%<-------------
#!/usr/bin/perl
use strict;
use warnings;

use PDL;
use PDL::NiceSlice;
use Inline qw(Pdlpp);

# Build the array of data
my $var1 = pdl q[ 111 121 131 ; 211 221 231 ]
my $var2 = pdl q[ 112 122 132 ; 212 222 232 ]
my $var3 = pdl q[ 113 123 133 ; 213 223 233 ]
my $var4 = pdl q[ 114 124 134 ; 214 224 234 ]
my $data = cat($var1, $var2, $var3, $var4);

# At this point we would index $data by ($day, $cell, $var).
# So $data(1, 0, 2) would give the data for 2nd day,
# first cell, third variable. If you would prefer a different
# order, use mv, xchg, or reorder to move the indices about.

# Now simply call the hammer function, which is defined below.
my $results = $data->my_hammer;

# $results holds the intended results of you calculation.
# Now you just need to save the results, or print them,
# or plot them, or do whatever you do with the processed data.

__DATA__

__Pdlpp__

pp_def('my_hammer',
        Pars => 'data(day, cell, var), [o] results(dimension list)',
        Code => q{
                // Quasi-C-code to analyze your data goes here
                // see
http://search.cpan.org/~chm/PDL-2.4.6/Basic/Gen/Inline/Pdlpp.pm
                // and http://pdl.perl.org/?docs=PP&title=PDL::PP
                // for details
        },
        );

-------------%<-------------

Have fun!

David

-- 
Sent via my carrier pigeon.
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to