[Numpy-discussion] .byteswap() and copy/view dilemma
Francesc Altet
faltet at carabos.com
Wed Dec 13 11:28:01 CST 2006
Hi,
I'm a bit confused about which cases the .byteswap() method in NumPy
would return a copy or a view. From the docstrings:
"""
a.byteswap(False) -> View or copy. Swap the bytes in the array.
Swap the bytes in the array. Return the byteswapped array. If the
first argument is TRUE, byteswap in-place and return a reference to
self.
"""
>From the above description, it is not clear to me whether
the .byteswap(False) would return a copy or a view. However, the
official NumPy book seems to explain this clearer:
"""
Byteswap the elements of the array and return the byteswapped array. If
the argument is True, then byteswap in-place and return a reference to
self. Otherwise, return a copy of the array with the elements
byteswapped. The data-type descriptor is not changed so the array will
have changed numbers.
"""
My experiments also show that .byteswap(False) does do a copy:
In [154]:a=numpy.array([1,2,3])
In [155]:b=a.byteswap()
In [156]:b
Out[156]:array([16777216, 33554432, 50331648])
In [157]:a[1]=0
In [158]:b
Out[158]:array([16777216, 33554432, 50331648])
I'm wondering if I'm the only one that finds this docstring confusing.
Regards,
--
Francesc Altet | Be careful about using the following code --
Carabos Coop. V. | I've only proven that it works,
www.carabos.com | I haven't tested it. -- Donald Knuth
More information about the Numpy-discussion
mailing list