[Numpy-discussion] Question about flags of fancy indexed array
Anne Archibald
peridot.faceted at gmail.com
Wed May 23 10:44:53 EDT 2007
On 23/05/07, Albert Strasheim <fullung at gmail.com> wrote:
> If you are correct that this is in fact a fresh new array, I really
> don't understand where the values of these flags. To recap:
>
> In [19]: x = N.zeros((3,2))
>
> In [20]: x.flags
> Out[20]:
> C_CONTIGUOUS : True
> F_CONTIGUOUS : False
> OWNDATA : True
> WRITEABLE : True
> ALIGNED : True
> UPDATEIFCOPY : False
>
> In [21]: x[:,[1,0]].flags
> Out[21]:
> C_CONTIGUOUS : False
> F_CONTIGUOUS : True
> OWNDATA : False
> WRITEABLE : True
> ALIGNED : True
> UPDATEIFCOPY : False
>
> So since x and x[:,[1,0]] are both new arrays, shouldn't their flags be
> identical? I'd expect at least C_CONTIGUOUS and OWNDATA to be True.
It looks like x[:,[1,0]] is done by fancy indexing on the first index
and then transposing. I haven't looked at the implementation, though.
If you need the result to be C-contiguous without further copying, you
can do:
x.transpose()[[1,0],:].transpose().flags
which is horrible. I wouldn't rely on it, though, I'd use
asconguousarray afterward.
Perhaps Travis could comment on whether it is true that numpy does
transpose like this when fancy indexing (at least, this flavour of
fancy indexing).
Anne
More information about the NumPy-Discussion
mailing list