[SciPy-user] variable (undetermined at initialization) dimensionof an array ?
ferrell at diablotech.com
ferrell at diablotech.com
Fri Aug 22 09:23:36 EDT 2003
Nils Wagner writes:
<snip>
> 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 ?
I would think that in this case you'd want to create a as a list, and
then after the loop create the array. The experts may need to correct
me, but I expect that the resize will cause a copy of the data each
iteration. If you use a list that copy won't be done. After the loop
you can then copy the contents of the list to an array.
aList = []
while f < eps:
aList += [somevalue]
a = array(aList)
-robert
More information about the SciPy-User
mailing list