[Numpy-tickets] [NumPy] #1012: dtype attributes change after an arithmetic operation involving a scalar

NumPy numpy-tickets@scipy....
Thu Feb 19 16:20:59 CST 2009


#1012: dtype attributes change after an arithmetic operation involving a scalar
------------------------+---------------------------------------------------
 Reporter:  hana        |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:  1.3.0   
Component:  numpy.core  |     Version:  none    
 Severity:  normal      |    Keywords:          
------------------------+---------------------------------------------------
 If you add an integer scalar to an integer array, the resulting array
 changes the attributes 'num' and 'char' of dtype:

 >>> from numpy import array
 >>> a = array([1,2])
 >>> b = 0+a
 >>> a.dtype.num
 7
 >>> b.dtype.num
 5
 >>> a.dtype.char
 'l'
 >>> b.dtype.char
 'i'

 This has an effect on scipy.ndimage functions:

 >>> from scipy import ndimage
 >>> ndimage.sum(a)
 3.0
 >>> ndimage.sum(b)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5
 /site-packages/scipy/ndimage/measurements.py", line 126, in sum
     return _nd_image.statistics(input, labels, index, 0)
 RuntimeError: data type not supported

 Note that if you do b=a+0 (instead of b=0+a), it works.

 We are running python 2.5, numpy 1.2.1, scipy 0.7.0

-- 
Ticket URL: <http://scipy.org/scipy/numpy/ticket/1012>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list