Re: numeric module

2005-04-01 Thread David M. Cooke
"coffeebug" <[EMAIL PROTECTED]> writes:

> I cannot import "numarray" and I cannot import "numeric" using python
> 2.3.3

numarray and Numeric are separate modules available at 
http://numpy.sourceforge.net/

If you're doing anything numerical in Python, you'll want them :-)

-- 
|>|\/|<
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread David M. Cooke
[EMAIL PROTECTED] 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> What's the problem with this code? I get the following error message:

2.4 or earlier?

> File "test.py", line 26, in test
>print tbl[wi][bi]
> IndexError: index must be either an int or a sequence

Longs are not ints; message implies that Numeric, unlike Python, does not 
allow them as indexes.

> from Numeric import *
> tbl = zeros((32, 16))
>
> def test():
>
>val = testme()

val is never used

>wi = crc >> 4

crc is never set, so how did this run?

>bi = crc & 0xFL

making bi a long.  Try 0xF which should be faster anyway.

>print wi
>print bi
print type(wi), type(bi)
>print tbl[wi][bi]
>
> def testme():
>val = 0xFFL
>val >>= 23
>return val
>
> if __name__ == '__main__':
>test()



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread coffeebug
I cannot import "numarray" and I cannot import "numeric" using python
2.3.3

Where would I find an equivalent definition for zeros()?

Anyway, is there supposed to be something that sets the value of
elements of tbl to values other than zero? Not that the question has
anything to do with  Shama's problem (recognizing tbl as a
two-dimensional array).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread shama . bell
Thanks Steve.

There's a problem with Numeric array. I tried with numarray and it
works fine.

-SB

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
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 = crc >> 4
bi = crc & 0xFL
print wi
print bi
print tbl[wi][bi]
def testme():
val = 0xFFL
val >>= 23
return val

if __name__ == '__main__':
test()
Hmm...  I can't reproduce this with numarray.  Maybe this only exists in 
Numeric?  Are you sure that the code here is what produced the error?

py> import numarray as na
py> tbl = na.zeros((32, 16))
py> def test():
... val = testme()
... wi = val >> 4
... bi = val & 0xFL
... print wi
... print bi
... print tbl[wi][bi]
...
py> def testme():
... val = 0xFFL
... val >>= 23
... return val
...
py> test()
0
1
0
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread shama . bell
The table initializes to a 2 dimensional with zeros.
-SB

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread coffeebug
I don't know much here...but is there an assumption you're making about
the machine word size to be greather than 24 bits?
Also, more to the point, does the function zeros() instantiate a
two-dimensional table? If so, does it populate the table with any
values?  The error looks like tbl[ ][ ] doesn't get defined.
Thanks for patience!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric module

2005-04-01 Thread shama . bell
In function test(),
Read wi and bi as:
wi = val >> 4
bi = val & 0xFL

-SB

-- 
http://mail.python.org/mailman/listinfo/python-list


numeric module

2005-04-01 Thread shama . bell
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 = crc >> 4
bi = crc & 0xFL
print wi
print bi
print tbl[wi][bi]


def testme():
val = 0xFFL
val >>= 23
return val


if __name__ == '__main__':
test()

Thanks,
-SB

-- 
http://mail.python.org/mailman/listinfo/python-list