[Numpy-discussion] Using as_strided to avoid copy on repeat (with 2-dimensional array)

Nicolas Rougier Nicolas.Rougier@inria...
Mon Aug 12 16:01:26 CDT 2013


I have a (n,2) shaped array representing points and I would like to double each point as in:

A = np.arange(10*2).reshape(10,2)
B = np.repeat( A, 2, axis=0 )

Is it possible to do the same using 'as_strided' to avoid copy (and still get the same output shape for B) ?

I found this reference:

but did not manage to adapt it to my case.

Bonus question (if previous 'as_strided' trick is possible), would this work or do I need a different construct ?

A = np.arange(10*2).reshape(10,2)
B = np.repeat( A[::2], 2, axis=0 )


More information about the NumPy-Discussion mailing list