[Numpy-tickets] [NumPy] #524: Scalar arithmetic with arrays produces values that masquerade as a particular type but are not
NumPy
numpy-tickets@scipy....
Mon May 21 17:17:23 CDT 2007
#524: Scalar arithmetic with arrays produces values that masquerade as a
particular type but are not
--------------------+-------------------------------------------------------
Reporter: socha | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: Other | Version: 1.0.2
Severity: normal | Keywords:
--------------------+-------------------------------------------------------
Multiplication and addition of scalars with arrays produces values that
say they are of a particular type but are not actually of that type.
Here's an example:
{{{
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\socha>python
Python 2.4.3 - Enthought Edition 1.0.0 (#69, Aug 2 2006, 12:09:59) [MSC
v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.0.2'
>>> from numpy import array
>>> a = array([1000])
>>> b = 1000*array([1])
>>> type(a[0]) == type(b[0])
False
>>> type(a[0])
<type 'numpy.int32'>
>>> type(b[0])
<type 'numpy.int32'>
>>> from numpy import int32
>>> type(a[0]) == int32
True
>>> type(b[0]) == int32
False
>>> b = array([1000])
>>> type(b[0]) == int32
True
>>> type(a[0]) == type(b[0])
True
>>> c = 1000+array([1]) # also happens for '+'
>>> c
array([1001])
>>> type(c[0]) == int32
False
>>>
}}}
Daniel Terhorst and David Socha ([http://www.urbansim.org UrbanSim])
--
Ticket URL: <http://www.projects.scipy.org/scipy/numpy/ticket/524>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list