Numeric and the new division operator
Michael James Barber
mjbarber at ascc.artsci.wustl.edu
Thu Jan 3 09:54:22 EST 2002
I run into a problem when using the new "true division" operator in
conjunction with Numeric. Do others see this too?
I can't imagine what I could be doing wrong with what is below, but I hope
someone can enlighten me if it is a usage problem. The problem is only in
Numeric, btw - it works fine with floats and integers.
Python 2.2 (#124, Dec 22 2001, 17:36:41) [CW CARBON GUSI2 THREADS GC] on
mac
Type "copyright", "credits" or "license" for more information.
>>> from Numeric import arange
>>> x = arange(10)
>>> x
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> x / 10
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> x / 10.
array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
>>> # classic division works as expected
...
>>> # now let's try true division
...
>>> from __future__ import division
>>> x/10
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for /: 'array' and 'int'
>>> x / 10.
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for /: 'array' and 'float'
>>> # oh, dear
--
Michael J. Barber
More information about the Python-list
mailing list