[Numpy-discussion] "formstring()" in place?

Chris Barker cbarker at jps.net
Fri Nov 3 13:28:55 CST 2000


"Paul F. Dubois" wrote:
> >>> y=array([1,2,3], '1')
> >>> y
> array([1, 2, 3],'1')
> >>> y.astype(Int32)
> array([1, 2, 3],'i')

Actually, this is exactly NOT what I want to do. In this case, each 1
byte interger was converted to a 4byte integer, of the same VALUE. What
I want is to convert each SET of four bytes into a SINGLE 4 byte integer
as it:

>>> a = array([1,2,3,4],'1')
>>> a = fromstring(a.tostring(),Int32)
>>> a
array([67305985],'i')   

The four one byte items in a are turned into one four byte item. What I
want is to be able to do this in place, rather than have tostring()
create a copy. I think fromstring may create a copy as well, having a
possible total of three copies around at once. Does anyone know how many
copies will be around at once with this line of code?

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
cbarker at jps.net                      ---           ---           ---
http://www.jps.net/cbarker          -----@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Water Resources Engineering       ------   @    ------   @   ------   @
Coastal and Fluvial Hydrodynamics -------      ---------     --------    
------------------------------------------------------------------------
------------------------------------------------------------------------



More information about the Numpy-discussion mailing list