How about
pdl> $a=pdl(1,2,3)
pdl> p pdl($a(*3),$a(:,*3))->flat
[1 1 1 2 2 2 3 3 3 1 2 3 1 2 3 1 2 3]
pdl>
though you might prefer
pdl> p append($a(*3)->flat,$a(:,*3)->flat)
[1 1 1 2 2 2 3 3 3 1 2 3 1 2 3 1 2 3]
to avoid problems when the shapes of the intermediate arrays are
incompatible. The *3 inserts a dummy dimension of size 3 in the first
place, producing three identical columns, while :,*3 produces a dummy
dimension of size 3 as the second index, so you produce tree identical
columns,
pdl> p $a(*3)
[
[1 1 1]
[2 2 2]
[3 3 3]
]
pdl> p $a(:,*3)
[
[1 2 3]
[1 2 3]
[1 2 3]
]
->flat makes them 1D and append puts one after the other.
Regards,
Luis
On Sat, Jul 13, 2019 at 02:54:34PM -0400, Robert Ryley wrote:
> I've been working on translating some NumPY examples into PDL. There
> has been some positive reinforcement on Perl Monks as can be seen
> here:
>
> https://www.perlmonks.org/?node_id=1233413
>
> I am stuck on the following NumPy example:
>
> Q. Create the following pattern without hardcoding. Use only numpy
> functions and the below input array a.
>
> Input:
> a = np.array([1,2,3])`
>
> Desired Output:
> array([1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3])
>
> Solution
> np.r_[np.repeat(a, 3), np.tile(a, 3)]
> #> array([1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3])
>
> Does PDL have something equivalent to NumPy's "tile" function? I've
> looked through the docs and do not see anything obvious to solve the
> problem.
>
>
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general
>
--
o
W. Luis Mochán, | tel:(52)(777)329-1734 /<(*)
Instituto de Ciencias Físicas, UNAM | fax:(52)(777)317-5388 `>/ /\
Apdo. Postal 48-3, 62251 | (*)/\/ \
Cuernavaca, Morelos, México | [email protected] /\_/\__/
GPG: 791EB9EB, C949 3F81 6D9B 1191 9A16 C2DF 5F0A C52B 791E B9EB
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general