Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > NumPy Question - numpy.put in multi-dimensional array

Reply
Thread Tools

NumPy Question - numpy.put in multi-dimensional array

 
 
Bryan.Fodness@gmail.com
Guest
Posts: n/a
 
      11-13-2007
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

 
Reply With Quote
 
 
 
 
davisn90210@gmail.com
Guest
Posts: n/a
 
      11-13-2007
On Nov 13, 1:22 pm, "(E-Mail Removed)"
<(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      11-13-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sum returns numpy.float64 when applied to a sequence of numpy.uint64 suzaku Python 0 12-15-2012 09:40 AM
Installing numpy over an older numpy Tom Kacvinsky Python 1 06-15-2012 07:15 PM
A More Concise Description of Numpy than the Guide to Numpy? W. eWatson Python 2 11-23-2009 08:58 PM
numpy migration (also posted to numpy-discussion) Duncan Smith Python 3 04-25-2007 01:36 AM
Trouble with numpy-0.9.4 and numpy-0.9.5 drife Python 1 03-01-2006 05:59 PM



Advertisments