[Numpy-discussion] Question about flags of fancy indexed array

Timothy Hochberg tim.hochberg at ieee.org
Wed May 23 12:00:57 EDT 2007


I'm not sure why the data ends up F_CONTIGUOUS, but it appears that you can
get things to end up as C_CONTIGUOUS by transposing before the indexing and
then transposing back. I don't think that this results in extra copies, but
I'm not certain of that.

>>> a = np.arange(6).reshape(3,2)
>>> a
array([[0, 1],
       [2, 3],
       [4, 5]])
>>> b1 = a[:,[1,0]]
>>> a.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False
>>> b1.flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False
>>> b2 = a.transpose()[[(1,0)]].transpose()
>>> b2.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False
>>> b1 == b2
array([[True, True],
       [True, True],
       [True, True]], dtype=bool)


-- 

//=][=\\

tim.hochberg at ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070523/64353126/attachment.html>


More information about the NumPy-Discussion mailing list