[Numpy-discussion] optional arguments to the array constructor
Philip Austin
paustin at eos.ubc.ca
Tue Jul 6 18:43:49 EDT 2004
(for numpy v1.0 on Mandrake 10 i686)
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? 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.
Thanks for any insights -- Phil
More information about the NumPy-Discussion
mailing list