471,325 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

NumPy Question - numpy.put in multi-dimensional array

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

Nov 13 '07 #1
2 3752
On Nov 13, 1:22 pm, "Bryan.Fodn...@gmail.com"
<Bryan.Fodn...@gmail.comwrote:
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

Nov 13 '07 #2
Br***********@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?
numpy questions are best asked on the numpy mailing list.

http://www.scipy.org/Mailing_Lists
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
In this case, you don't really want put(). Just use indexing:

for i in range(2):
for j in range(iy):
a[i,39-j] = 1

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Nov 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by mclaugb | last post: by
1 post views Thread by drife | last post: by
15 posts views Thread by nikie | last post: by
13 posts views Thread by Gary Wessle | last post: by
10 posts views Thread by Bryan | last post: by
15 posts views Thread by greg.landrum | last post: by
reply views Thread by robert | last post: by
3 posts views Thread by Juergen Kareta | last post: by
3 posts views Thread by Duncan Smith | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.