[Numpy-discussion] Using as_strided to avoid copy on repeat (with 2-dimensional array)
Nicolas Rougier
Nicolas.Rougier at inria.fr
Mon Aug 12 17:01:26 EDT 2013
Hi,
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:
http://stackoverflow.com/questions/5564098/repeat-numpy-array-without-replicating-data
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 )
Nicolas
More information about the NumPy-Discussion
mailing list