NumPy Question - numpy.put in multi-dimensional array

B

Bryan.Fodness

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,[39-j],[1])

but,

Traceback (most recent call last):
put(a,[39 - j],[1])
IndexError: list index out of range
 
D

davisn90210

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,[39-j],[1])

but,

Traceback (most recent call last):
put(a,[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
 
R

Robert Kern

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,[39-j],[1])

but,

Traceback (most recent call last):
put(a,[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top