The "pdl" constructor does not replicate values to match dimensions but pads them instead. In contrary, "cat" works as expected:

pdl> do_print 1
1

pdl> $v = sequence 2
[0 1]

pdl> cat $v(,*1), $v(*1,)

[
 [
  [0 1]
  [0 1]
 ]
 [
  [0 0]
  [1 1]
 ]
]

Best regards,
-jo

On Tue 19 Aug 2025 07:09:32 PM CEST, Luis Mochan <[email protected]> wrote:

I'm confused by variations of the following program:
use v5.36;
use PDL;
use PDL::NiceSlice;
my $v=sequence(2);
my $m=pdl($v->slice(":,*2"), $v->slice("*2,:"));
say $m;

The output is

   [
    [
     [0 1]
     [0 1]
    ]
    [
     [0 0]
     [1 1]
    ]
   ]

which is what I expected. But after a small change:

use v5.36;
use PDL;
use PDL::NiceSlice;
my $v=sequence(2);
my $m=pdl($v->slice(":,*"), $v->slice("*,:"));
say $m;

the output becomes


[
 [
  [0 1]
  [0 0]
 ]
 [
  [0 0]
  [1 0]
 ]
]

The same if I replace * by *1. Was I wrong to expect the same output?
I expected the dummy dimension of size 1 (or unspecified size) would
lead to  the initial array [0 1] being replicated as many times as
required by the actual dimensions of the other arrays.

Best regards,
Luis




_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to