Automatic copies of NumPy arrays
Jan Kybic
Jan.Kybic at epfl.ch
Fri Oct 20 05:00:48 EDT 2000
Hello,
I have recently switched from Matlab to Numeric
Python. Overall the experience has been largely positive: Python is so
much better suited for bigger projects. However, one of the things
that is bothering me, is that in NumPy, I have to decide, whether I
want to pass arrays directly or as copies. Whether I should write
call to myfunc() as:
myfunc(x) or myfunc(array(x))
The first variant is clearly faster but I need to know that either
myfunc does not change x, or that x is no longer needed afterwards. In
Matlab this was handled for me automatically. I just wandered, if
anybody has also found it to be a problem, and if they perhaps had a
solution. I thought along the lines of subclassing arrays to be
unmutable such as:
...
myfunc(unmutable(x))
...
with corresponding definition:
def myfunc(x):
x=makemutable(x)
...
def makemutable(x):
if not mutable(x):
return array(x)
return x
Any comments
--
-------------------------------------------------------------------------
Jan Kybic <Jan.Kybic at epfl.ch> BIG IOA DMT EPFL Lausanne, Switzerland
or <kybic at ieee.org> tel. work +41 (21) 693 5142
For PGP key see my WWW page. http://bigwww.epfl.ch/kybic
More information about the Python-list
mailing list