On 5/23/07, Anne Archibald <[EMAIL PROTECTED]> wrote:

On 23/05/07, Albert Strasheim <[EMAIL PROTECTED]> 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.


Both copy and ascontiguousarray do the job:

In [39]: ascontiguousarray(x[:,[1,0]]).flags
Out[39]:
 C_CONTIGUOUS : True
 F_CONTIGUOUS : False
 OWNDATA : True
 WRITEABLE : True
 ALIGNED : True
 UPDATEIFCOPY : False

In [40]: x[:,[1,0]].copy().flags
Out[40]:
 C_CONTIGUOUS : True
 F_CONTIGUOUS : False
 OWNDATA : True
 WRITEABLE : True
 ALIGNED : True
 UPDATEIFCOPY : False

The extra copy is unfortunate but I don't see how it is to be avoided.
Maintaining order and contiguity in memory is not the goal of numpy,
convenience and flexibility is. So interfacing with external C and FORTRAN
is always going to need some care.

Chuck
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to