[Numpy-discussion] Non-contiguous array from newaxis indexing
Jens Jørgen Mortensen
jensj@fysik.dtu...
Sat Aug 18 04:00:56 CDT 2007
I would like all these arrays to be contiguous:
>>> import numpy as npy
>>> npy.__version__
'1.0.4.dev3967'
>>> x = npy.arange(4)
>>> y = x[npy.newaxis, :]
>>> z = x.reshape((1, 4))
>>> for a in [x, y, z]:
... print a.shape, a.strides, a.flags.contiguous
...
(4,) (4,) True
(1, 4) (0, 4) False
(1, 4) (16, 4) True
But y is not contiguous according to y.flags.contiguous - why not and
why does y and z not have the same strides?
I found this comment just before the _IsContiguous function in
arrayobject.c:
/* 0-strided arrays are not contiguous (even if dimension == 1) */
Is this correct?
Jens Jørgen Mortensen
More information about the Numpy-discussion
mailing list