numeric module
David M. Cooke
cookedm+news at physics.mcmaster.ca
Fri Apr 1 16:10:12 EST 2005
shama.bell at gmail.com writes:
> Hello,
> What's the problem with this code? I get the following error message:
>
> File "test.py", line 26, in test
> print tbl[wi][bi]
> IndexError: index must be either an int or a sequence
>
> ---code snippet----
>
> from Numeric import *
> tbl = zeros((32, 16))
>
> def test():
>
> val = testme()
> wi = val >> 4
> bi = val & 0xFL
[above changed to use val instead of crc, as you mentioned in another post]
> print wi
> print bi
> print tbl[wi][bi]
tbl[wi][bi] would be indexing the bi'th element of whatever tbl[wi]
returns. For Numeric arrays, you need
tbl[wi,bi]
Now, you'll have another problem as Terry Reedy mentioned: the indices
(in Numeric) need to be Python ints, not longs. You could rewrite your
test() function as
def test():
val = testme()
wi = int(val >> 4)
bi = int(val & 0xF)
print wi
print bi
print tbl[wi,bi]
and that'll work.
--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
More information about the Python-list
mailing list