ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
[Numpy-discussion] .byteswap() and copy/view dilemma
by Francesc Altet other posts by this author
Dec 13 2006 9:28AM messages near this date
Re: [Numpy-discussion] rollaxis | [Numpy-discussion] Histograms of extremely large data sets
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

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

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved