Using as_strided to avoid copy on repeat (with 2-dimensional array)
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-replic... 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
On Mon, Aug 12, 2013 at 10:01 PM, Nicolas Rougier <Nicolas.Rougier@inria.fr> wrote:
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) ? No, this would not be uniformly strided in the 0 axis. -- Robert Kern
On Mon, Aug 12, 2013 at 11:23 PM, Robert Kern <robert.kern@gmail.com> wrote:
Is it possible to do the same using 'as_strided' to avoid copy (and still get the same output shape for B) ?
No, this would not be uniformly strided in the 0 axis.
Now, if only we supported simple fraction strides... Stéfan
participants (3)
-
Nicolas Rougier
-
Robert Kern
-
Stéfan van der Walt