# Numeric array and for loops problem

Terry Reedy tjreedy at udel.edu
Mon Jan 6 19:45:06 CET 2003

```"Stan" <dragonscraft at yahoo.it> wrote in message
> Hi all
>  I've made the following pice of code

[Note: if you want people with certain news readers to easily read

> try:
> f = open(os.path.join("xxx", fname))
> except IOError:
> print "no such a file"
> else:
> worldy = len(lines)
> worldx = len(lines[0])/2
> worldarray = Numeric.zeros((worldy,worldx))

Should you use wx,wy to match x,y below?

> y = -1 #***because arrays starts at 0***

If you increment x and y after you use them, you can start with 0

> for line in lines:
> y += 1
> vals = split(line)
> x = -1  #***same as y***
> for val in vals:
> x += 1
> worldarray[x,y] = val
> f.close()
>
> It should read some strings from a file and insert their value into
> worldarray
> The file is so strocturated:
> Some string of numbers (all same lenght) all separated by
whitespace.
> But python give me this message error!!! I really can't understand
> where's the matter? It's not possible such an assignment?

> worldarray[x,y] = val
> ValueError: array too large for destination

You initialized worldarray as an array of floats.  Perhaps you want

worldarray[x,y] = float(val)

Terry J. Reedy

```