Hello,
I am getting the following error when returning a list:
return tbl[c1,c2]
"IndexError: each subindex must be either a slice, an integer,
Ellipsis, or NewAxis"
What does it mean?
Here's the code snippet....
from Numeric import *
# Initialize the 32x16 global array to zeros
tbl = zeros((32, 16)
def getValue( value):
data = test(value)
c1 = data[0]
c2 = data[1]
print tbl[c1, c2]
def test( value):
t1 = 0x0
t2 = 0x1
return tbl[t1, t2]
Thanks,
-SB 5 1635 sh********@gmail.com wrote: from Numeric import *
# Initialize the 32x16 global array to zeros tbl = zeros((32, 16)
def getValue( value): data = test(value) c1 = data[0] c2 = data[1] print tbl[c1, c2]
def test( value): t1 = 0x0 t2 = 0x1 return tbl[t1, t2]
In test, tbl[0x0, 0x1] is just going to give you a single element of
tbl, in this case a 0. So data is a 0. data[0] and data[1] doesn't
really make much sense. Is this the code you actually get the
IndexError with? I'm using numarray, not Numeric, and I know there are
some differences, but the code above doesn't give me an IndexError:
py> import numarray as na
py> tbl = na.zeros((32, 16))
py> def get_value():
.... data = test()
.... c1 = data[0]
.... c2 = data[1]
.... print tbl[c1, c2]
....
py> def test():
.... t1 = 0x0
.... t2 = 0x1
.... return tbl[t1, t2]
....
py> get_value()
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 3, in get_value
TypeError: unsubscriptable object
STeVe
Steven Bethard wrote: sh********@gmail.com wrote: from Numeric import *
# Initialize the 32x16 global array to zeros tbl = zeros((32, 16)
def getValue( value): data = test(value) c1 = data[0] c2 = data[1] print tbl[c1, c2]
def test( value): t1 = 0x0 t2 = 0x1 return tbl[t1, t2] In test, tbl[0x0, 0x1] is just going to give you a single element of tbl, in this case a 0. So data is a 0. data[0] and data[1] doesn't really make much sense. Is this the code you actually get the IndexError with? I'm using numarray, not Numeric, and I know there
are some differences, but the code above doesn't give me an IndexError:
py> import numarray as na py> tbl = na.zeros((32, 16)) py> def get_value(): ... data = test() ... c1 = data[0] ... c2 = data[1] ... print tbl[c1, c2] ... py> def test(): ... t1 = 0x0 ... t2 = 0x1 ... return tbl[t1, t2] ... py> get_value() Traceback (most recent call last): File "<interactive input>", line 1, in ? File "<interactive input>", line 3, in get_value TypeError: unsubscriptable object
STeVe
What i was intending to do is return a list with row and column values.
data[0] and data[1] are the list values i get from test.
Whats the best way to read these row and column values in function
get_value() when i return the list (return tbl[t1, t2])
Thanks,
-SB sh********@gmail.com wrote: Steven Bethard wrote: py> import numarray as na py> tbl = na.zeros((32, 16)) py> def get_value(): ... data = test() ... c1 = data[0] ... c2 = data[1] ... print tbl[c1, c2] ... py> def test(): ... t1 = 0x0 ... t2 = 0x1 ... return tbl[t1, t2] ... py> get_value() Traceback (most recent call last): File "<interactive input>", line 1, in ? File "<interactive input>", line 3, in get_value TypeError: unsubscriptable object
What i was intending to do is return a list with row and column values.
data[0] and data[1] are the list values i get from test.
Whats the best way to read these row and column values in function get_value() when i return the list (return tbl[t1, t2])
Still not sure I understand you. Are you wanting c1 and c2 to retrieve
the values that t1 and t2 had? (That is, 0x0 and 0x1?) Or do you want
c1 and c2 to hold the first row and the first column? Or something else?
STeVe
Thats right. I wanted c1 and c2 to retrieve the values returned by t1
and t2 . Values for t1 and t2 could be anything. Also tbl is global.
-SB sh********@gmail.com wrote: Thats right. I wanted c1 and c2 to retrieve the values returned by t1 and t2 . Values for t1 and t2 could be anything. Also tbl is global.
Then you need to return t1 and t2 in test, e.g.:
py> import numarray as na
py> tbl = na.zeros((32, 16))
py> def test():
.... t1 = 0x0
.... t2 = 0x1
.... return t1, t2, tbl[t1, t2]
....
py> def get_value():
.... c1, c2, data = test()
.... print tbl[c1, c2]
....
py> get_value()
0
Just as an element of any other container doesn't know what index it's
stored at, values in a numarray array don't either. If you want to deal
with indices, you need to either pass them around instead (or in
addition to) the values, or you need to search the whole array each time
for similar objects and see what indices they're at. The first approach
is probably preferred in most cases.
STeVe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ishwor |
last post by:
i am trying to remove an item 'e' from the list l but i keep getting IndexError.
I know the size of the list l is changing in the for loop & its sort
of trivial task but i found no other way than...
|
by: TB |
last post by:
Hi,
Is there an elegant way to assign to a list from a list of unknown
size? For example, how could you do something like:
>>> a, b, c = (line.split(':'))
if line could have less than three...
|
by: erikwickstrom |
last post by:
Hi all,
I'm sorry about the newbie question, but I've been searching all
afternoon and can't find the answer!
I'm trying to get this bit of code to work without triggering the
IndexError.
...
|
by: DarrenWeber |
last post by:
# Copyright (C) 2007 Darren Lee Weber
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |