Re: [Numpy-discussion] array not appending

2008-12-18 Thread Robert Kern
On Thu, Dec 18, 2008 at 07:58, David Cournapeau wrote: > 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 ma

Re: [Numpy-discussion] array not appending

2008-12-18 Thread Ravi
On Thursday 18 December 2008 08:00:09 Sebastian Haase wrote: > So the question remains: how to create an array of "empty" (i.e. 0) size ? In [1]: from numpy import * In [2]: x = array( [] ) In [3]: x Out[3]: array([], dtype=float64) In [4]: x.size Out[4]: 0 In [5]: x.shape Out[5]: (0,) In [6]

Re: [Numpy-discussion] array not appending

2008-12-18 Thread David Cournapeau
Sebastian Haase wrote: > On Thu, Dec 18, 2008 at 11:44 AM, David Cournapeau > 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. >>> >>> W

Re: [Numpy-discussion] array not appending

2008-12-18 Thread Alan G Isaac
On 12/18/2008 5:56 AM Prashant Saxena apparently wrote: > ST = np.empty((), dtype=np.float32) > ST = np.append(ST, 10.0) If you really need to append elements, you probably want to use a list and then convert to an array afterwards. But if you know your array size, you can preallocate memory and

Re: [Numpy-discussion] array not appending

2008-12-18 Thread Sebastian Haase
On Thu, Dec 18, 2008 at 11:44 AM, David Cournapeau 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

Re: [Numpy-discussion] array not appending

2008-12-18 Thread 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

Re: [Numpy-discussion] array not appending

2008-12-18 Thread Prashant Saxena
December, 2008 4:20:49 PM Subject: Re: [Numpy-discussion] array not appending On Thu, Dec 18, 2008 at 04:19:20PM +0530, Prashant Saxena wrote: >How do I solve this? If you want appending in place you have to use a python list. If you don't need modification in place, np.append returns

Re: [Numpy-discussion] array not appending

2008-12-18 Thread Gael Varoquaux
On Thu, Dec 18, 2008 at 04:19:20PM +0530, Prashant Saxena wrote: >How do I solve this? If you want appending in place you have to use a python list. If you don't need modification in place, np.append returns an array with the appended number. Gaƫl _

Re: [Numpy-discussion] array not appending

2008-12-18 Thread Prashant Saxena
How do I solve this? Thanks Prashant From: Gael Varoquaux To: Discussion of Numerical Python Sent: Thursday, 18 December, 2008 4:03:34 PM Subject: Re: [Numpy-discussion] array not appending On Thu, Dec 18, 2008 at 03:52:23PM +0530, Prashant Saxena wrote

Re: [Numpy-discussion] array not appending

2008-12-18 Thread Gael Varoquaux
On Thu, Dec 18, 2008 at 03:52:23PM +0530, Prashant Saxena wrote: >In [43]: ST = np.empty([], dtype=np.float32) >In [44]: np.append(ST, 10.0) >Out[44]: array([ 3.8603e-38, 1.e+01]) >In [45]: np.append(ST, 10.0) >Out[45]: array([ 3.8603e-38, 1.e+01]

[Numpy-discussion] array not appending

2008-12-18 Thread Prashant Saxena
Hi, This is copied from ipython console. In [42]: import numpy as np In [43]: ST = np.empty([], dtype=np.float32) In [44]: np..append(ST, 10.0) Out[44]: array([ 3.8603e-38, 1.e+01]) In [45]: np.append(ST, 10.0) Out[45]: array([ 3.8603e-38, 1.e+01]) In [46]: prin