NumPy Question - numpy.put in multi-dimensional array

davisn90210 at gmail.com davisn90210 at gmail.com
Tue Nov 13 23:23:40 CET 2007


On Nov 13, 1:22 pm, "Bryan.Fodn... at gmail.com"
<Bryan.Fodn... at gmail.com> wrote:
> from numpy import *
>
> a = zeros((2,40), int)
>
> fields = {}
> field = 10
> fields[field] = '30A', 5
>
> iy = int(fields[field][1])
> ix = int(fields[field][0].rstrip('AB'))
>
> for i in range(2):
>   for j in range(iy):
> #        put(a,[39 - j],[1])         #1d
>
> Can someone help me figure out how I would do it for multiple rows?
>
> I thought,
>
>        put(a,[i][39-j],[1])
>
> but,
>
> Traceback (most recent call last):
>   put(a,[i][39 - j],[1])
> IndexError: list index out of range

Try
    put(a, [(i, 39-j)], [1]
Note, however, that in this case you could just as easily use
    a[i, 39-j] = 1
instead.

--Nathan Davis




More information about the Python-list mailing list