[Numpy-discussion] indexing question

josef.pktd@gmai... josef.pktd@gmai...
Sun Dec 20 22:35:29 CST 2009


On Sun, Dec 20, 2009 at 8:58 PM, Alan G Isaac <aisaac@american.edu> wrote:
> Why is s3 F_CONTIGUOUS, and perhaps equivalently,
> why is its C_CONTIGUOUS data in s3.base (below)?
> Thanks,
> Alan Isaac
>
>>>> a3
> array([[ 0,  1,  2,  3,  4,  5],
>        [ 6,  7,  8,  9, 10, 11]])
>>>> a3.flags
>   C_CONTIGUOUS : True
>   F_CONTIGUOUS : False
>   OWNDATA : True
>   WRITEABLE : True
>   ALIGNED : True
>   UPDATEIFCOPY : False
>>>> ind
> array([3, 1, 2, 4, 5, 0])
>>>> s3 = a3[:,ind]
>>>> s3.flags
>   C_CONTIGUOUS : False
>   F_CONTIGUOUS : True
>   OWNDATA : False
>   WRITEABLE : True
>   ALIGNED : True
>   UPDATEIFCOPY : False
>>>> s3.base
> array([[ 3,  9],
>        [ 1,  7],
>        [ 2,  8],
>        [ 4, 10],
>        [ 5, 11],
>        [ 0,  6]])
>>>> s3
> array([[ 3,  1,  2,  4,  5,  0],
>        [ 9,  7,  8, 10, 11,  6]])

Maybe another consequence of the different internal treatment of fancy
and non-fancy slicing. I would infer from a comment by Travis in
response to the question about the change in axis for 3d arrays with
mixed fancy and non-fancy slicing.

>>> ind = np.array([3, 1, 2, 4, 5, 0])
>>> s3 = a[:,ind]
>>> s3.flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

>>> s4 = a[np.arange(2)[:,None],ind]
>>> s4.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

Josef


>>>>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list