[Numpy-discussion] repeat array in a fake dim without stride_tricks ?

Pierre Haessig pierre.haessig at crans.org
Thu Dec 12 09:20:05 EST 2013


In order to repeat rows or columns of an array as
I can use np.repeat as suggested by pv. However, looking at the flags of
the resulting array, data seems to be copied and actually repeated in
memory. This is not applicable if want a 1000x repetition.

What are the other options for such a repeat ?

On scipy lectures, there is a suggestion to use as_strided :

Otherwise, I see broadcast_arrays :

> N = 3
> data = np.arange(N)
> np.broadcast_arrays(data[:,None], np.zeros((1,2)))[0]
array([[0, 0],
       [1, 1],
       [2, 2]])

This works but it feels like invoking a magic formula. Did I miss a
simpler function ?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pierre_haessig.vcf
Type: text/x-vcard
Size: 329 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131212/4927c845/attachment.vcf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 897 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131212/4927c845/attachment.sig>

More information about the NumPy-Discussion mailing list