[SciPy-user] variable (undetermined at initialization) dimensionof an array ?

Pearu Peterson pearu at scipy.org
Fri Aug 22 06:53:54 EDT 2003


On Fri, 22 Aug 2003, Nils Wagner wrote:

> from scipy import *
> a=array([])
> ic = 0
> eps = 1.e-10
> f = 1.0
> i = 0
> while f < eps:
>   ic = ic + 1
>   a.resize((ic,))
>   a[i] = somevalue
>   i = i + 1
> 
> # f will be changed somehow in this loop
> 
> print a
> 
> Is this an effective way to implement it ?

Using Python lists might provide a cleaner code:

a = []
while f<eps:
  #calculate f,somevalue
  a.append(somevalue)
a = array(a)

Pearu




More information about the SciPy-User mailing list