[Numpy-discussion] np.array execution path
Sebastian Berg
sebastian at sipsolutions.net
Sat Sep 22 14:01:21 EDT 2012
Hi,
I have a bit of trouble figuring this out. I would have expected
np.asarray(array) to go through ctors, PyArray_NewFromArray, but it
seems to me it does not, so which execution path is exactly taken here?
The reason I am asking is that I want to figure out this behavior/bug,
and I really am not sure which function is responsible:
In [69]: o = np.ones(3)
In [70]: no = np.asarray(o, order='C')
In [71]: no[:] = 10
In [72]: o # OK, o was changed in place:
Out[72]: array([ 10., 10., 10.])
In [73]: no.flags # But no claims to own its data!
Out[73]:
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
In [74]: no = np.asarray(o, order='F')
In [75]: no[:] = 11
In [76]: o # Here asarray actually returned a real copy!
Out[76]: array([ 10., 10., 10.])
Thanks,
Sebastian
More information about the NumPy-Discussion
mailing list