[PYTHON MATRIX-SIG] Array -> String: array length
viennet@ura1507.univ-paris13.fr
viennet@ura1507.univ-paris13.fr
Thu, 8 May 1997 12:03:27 +0100 (WET DST)
Jean-Bernard ADDOR writes:
>
> I am very happy to hear about the length of the numpy arrays other users
> uses because I uses these day pow(2,22) = len(array) = 4194304 and I
> seriously ask me questions about python memory managment. My program uses
> hundreds Megs of RAM. My question is how many memory uses a
> Numeric.array(pow(2,22), Numeric.Float) is it much more than pow(2,24)
> bytes ?
No. You mean:
x = zeros( pow(2,22), Float )
which takes exactly 8 x 2^22 = 32Mo.
I frequently use NumPy with large arrays (like 10^5 x 256 matrix).
One must be aware of the following points:
- there is currently no way to create an unitialized array;
- operations like x = x + b allocate temporary arrays for
intermediate results. ufuncs (add, multiply) an be called
with a third argument specifying the destination array:
the form add( x, b, x )
will avoid unnecessary memory allocations.
- I/O usualy involve duplication of the data (conversion from/to
strings). A few months ago, there were interesting discussions
about a general "buffer" mecanism, but nobody took the time to
implement it.
- If you computes with float values, you may want to use the Float32
typecode (single precision) to save space (in this case, be careful
with automatic conversions towards double precision during
operation with scalar values).
Bonne chance
Emmanuel
--
Emmanuel Viennet: <viennet@ura1507.univ-paris13.fr>
LIPN - Institut Galilee - Universite Paris-Nord
93430 Villetaneuse - France
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________