
On Tue, 2004-07-06 at 21:42, Philip Austin wrote:
(for numpy v1.0 on Mandrake 10 i686)
My guess is you're talking about numarray here. Please be charitable if I'm talking out of turn... I tend to see everything as a numarray issue.
As noted on p. 25 the array constructor takes up to 5 optional arguments
array(sequence=None, type=None, shape=None, copy=1, savespace=0,typecode=None) (and raises an exception if both type and typecode are set).
Is there any way to make an alias (copy=0) of an array without passing keyword values?
In numarray, all you have to do to get an alias is:
b = a.view()
It's an alias because:
b._data is a._data True
That is, specifying the copy keyword alone works:
test=N.array((1., 3), "Float64", shape=(2,), copy=1, savespace=0) a=N.array(test, copy=0) a[1]=999 print test
[ 1. 999.]
But when intervening keywords are specified copy won't toggle:
test=N.array((1., 3)) a=N.array(sequence=test, type="Float64", shape=(2,), copy=0) a[1]=999. print test
[ 1. 3.]
Which is also the behaviour I see when I drop the keywords:
test=N.array((1., 3)) a=N.array(test, "Float64", (2,), 0) a[1]=999. print test
[ 1. 3.]
an additional puzzle is that adding the savespace parameter raises the following exception:
a=N.array(test, "Float64", (2,), 0,0) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.3/site-packages/numarray/numarraycore.py", line 312, in array type = getTypeObject(sequence, type, typecode) File "/usr/lib/python2.3/site-packages/numarray/numarraycore.py", line 256, in getTypeObject rtype = _typeFromTypeAndTypecode(type, typecode) File "/usr/lib/python2.3/site-packages/numarray/numarraycore.py", line 243, in _typeFromTypeAndTypecode raise ValueError("Can't define both 'type' and 'typecode' for an array.") ValueError: Can't define both 'type' and 'typecode' for an array.
All this looks like a documentation problem. The numarray array() signature has been tortured by Numeric backward compatibility, so there has been more flux in it than you would expect. Anyway, the manual is out of date. Here's the current signature from the code: def array(sequence=None, typecode=None, copy=1, savespace=0, type=None, shape=None): Sorry about the confusion, Todd