[Numpy-discussion] array not appending

David Cournapeau david@ar.media.kyoto-u.ac...
Thu Dec 18 07:58:00 CST 2008

Sebastian Haase wrote:
> On Thu, Dec 18, 2008 at 11:44 AM, David Cournapeau
> <david@ar.media.kyoto-u.ac.jp> wrote:
>> 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).
>> David
> So the question remains: how to create an array of "empty" (i.e. 0) size ?

The thing is I am not sure it is possible at all - I just wanted to tell
the OP that empty does not create an empty array (without any items in it).

What would be the need for a 0 item array ? If the point is to append
some data without knowing in advance the size, a list is most likely
more adapted to the task. An array which cannot be indexed does not
sound that useful, but I may just lack some imagination :)



More information about the Numpy-discussion mailing list