[NumPy-Tickets] [NumPy] #2087: In-place math functions like exp(A, out=A) giving wrong results with integer arguments
NumPy Trac
numpy-tickets@scipy....
Tue Mar 20 18:39:40 CDT 2012
#2087: In-place math functions like exp(A, out=A) giving wrong results with
integer arguments
-------------------------+--------------------------------------------------
Reporter: chris | Type: defect
Status: new | Priority: normal
Milestone: Unscheduled | Component: numpy.matrixlib
Version: 1.6.1 | Keywords:
-------------------------+--------------------------------------------------
Given an input matrix A with dtype 'int64', a mathematical function
like exp incorrectly keeps the type of A as an integer type producing
a wrong result if used as an in-place operation
numpy.exp(A, out=A)
The other version utilising a new result matrix works correctly:
A = numpy.exp(A)
Tested on MacPort (Mac OS X 10.6.8), Python 2.7.2 and Python 3.2.2.
Example:
{{{
A = numpy.array([[1, 0],[0,1]])
A.dtype
->dtype('int64')
numpy.exp(A)
->array([[ 2.71828183, 1. ],
-> [ 1. , 2.71828183]]) # correct result
A = numpy.array([[1, 0],[0,1]])
numpy.exp(A, out=A)
->array([[2, 1],
-> [1, 2]]) # wrong result
A.dtype
-> dtype('int64')
A == numpy.array([[2, 1],[1,2]])
-> array([[ True, True],
-> [ True, True]], dtype=bool)
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2087>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list