Adding cc to perldl list

On Wed, Jan 18, 2012 at 11:41 AM, David Mertens
<[email protected]> wrote:
>
> Anjan -
>
> Just to clarify, this is an issue with how Perl handles interpolation. When 
> you say
>
> my $foo = 3;
> my $string = "to $foo, and beyond!";
>
> Perl interpolates the value of $foo into the string. If you printed $string, 
> you would get this:
>
> to 3, and beyond!
>
> However, if you use single quotes:
>
> my $foo = 3;
> my $string = 'to $foo, and beyond!';
>
> Perl does *not* interpolate the variable---it assumes you meant to have that 
> dollar sign. Printing $string will give you this:
>
> to $foo, and beyond!
>
> Slice needs to interpolate, so use double-quotes and it should work. Also, I 
> second Chris's recommendation: use PDL::NiceSlice.
>
> David
>
>
> On Wed, Jan 18, 2012 at 10:20 AM, Chris Marshall <[email protected]> 
> wrote:
>>
>> I recommend using PDL::NiceSlice in general but the
>> problem appears to be that you are trying to index a
>> slice using the string '$x' rather than the number you
>> want, i.e., "$x" which ends up as 1.
>>
>>> pdl> p $eigen_vec = floor(random(5,5)*10);
>>>
>>> [
>>>  [9 9 3 6 5]
>>>  [9 3 3 2 1]
>>>  [7 3 5 8 8]
>>>  [7 3 0 3 0]
>>>  [7 1 3 2 9]
>>> ]
>>>
>>>
>>> pdl> $x = 0 ; $y = 3 ; $z = 4 ;  # PDL uses zero-based indices
>>>
>>> pdl> p ':,$x'
>>> :,$x
>>>
>>> pdl> p ":,$x"
>>> :,0
>>>
>>> pdl> p $eigen_vec->slice(":,$x")  # original slice(string) syntax
>>>
>>> [
>>>  [9 9 3 6 5]
>>> ]
>>>
>>>
>>> pdl> p $eigen_vec(:,$x)  # the nice NiceSlice syntax
>>>
>>> [
>>>  [9 9 3 6 5]
>>> ]
>>>
>>>
>>>
>>
>> On Wed, Jan 18, 2012 at 10:42 AM, ANJAN PURKAYASTHA 
>> <[email protected]> wrote:
>> > Hello,
>> > I'm having problems with a rather simple problem.
>> > I have a set of eigenvectors in matrix form. I would like to extract 3 of
>> > these eigenvectors ( that correspond to the 3 largest eigenvalues). The
>> > eigenvectors are stored in rows 1, 4, and 5.  I assign these row numbers to
>> > three scalars: $x, $y, $z and enter the command:
>> > $ev_x= $eigen_vec->slice(':,$x');
>> > .....
>> >
>> > I get an error: Invalid slice str ':,$x': '$x' at XXXX.pl line 118, <F> 
>> > line
>> > 149.
>> >
>> > What is the correct command for extracting a row (or cloumn) from a PDL?
>> > Thanks
>> > Anjan
>> >
>> >
>> > _______________________________________________
>> > Perldl mailing list
>> > [email protected]
>> > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>> >
>>
>>
>> _______________________________________________
>> Perldl mailing list
>> [email protected]
>> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>>
>
>
>
> --
> Sent via my carrier pigeon.

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to