[Numpy-discussion] array not appending
Thu Dec 18 07:00:09 CST 2008
On Thu, Dec 18, 2008 at 11:44 AM, David Cournapeau
> Prashant Saxena wrote:
>> ST = np.empty((), dtype=np.float32)
>> ST = np.append(ST, 10.0)
>> This works, is it proper way to do so?
>> One more prob
>> ST.size returns 2.
>> Why? I have added only one element.
> You added one element to an array which as already one element. Empty
> does not mean that the array has no items (which is not possible AFAIK),
> but that the values are 'empty' (more exactly, they are undefined
> values, since the memory emplacement has not been initialized).
So the question remains: how to create an array of "empty" (i.e. 0) size ?
I guess, setting the first argument in empty (i.e. shape) to ()
produces a scalar value - which is probably what the one the OP saw.
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: len() of unsized object
Seems all correct. Now, however, to which axis is "append" appending
? Especially if the array doesn't have any axis (i.e. shape = () ).
I would argue that append should throw an exception here, rather than
"implicitely" changing shape to (1,) before appending -- this is most
likely not what the user intended, see OP.
More information about the Numpy-discussion