[NumPy-Tickets] [NumPy] #1487: vectorize(): result depends on execution order; is this normal?
NumPy Trac
numpy-tickets@scipy....
Fri May 21 09:14:05 CDT 2010
#1487: vectorize(): result depends on execution order; is this normal?
------------------------------+---------------------------------------------
Reporter: lebigot | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 2.0.0
Component: numpy.core | Version: 1.3.0
Keywords: vectorize, dtype |
------------------------------+---------------------------------------------
The dtype of the array returned by a vectorize()'d function depends on the
execution order:
Session 1:
{{{
In [1]: f_vec = vectorize(lambda x: x)
In [3]: f_vec(arange(3))
Out[3]: array([0, 1, 2])
In [4]: f_vec(arange(0.1, 3)) # floats
Out[4]: array([0, 1, 2]) # integers
}}}
Session 2:
{{{
In [1]: f_vec = vectorize(lambda x: x)
In [2]: f_vec(arange(0.1, 3)) # floats, same as above
Out[2]: array([ 0.1, 1.1, 2.1]) # floats, and not integers as above
}}}
Thus, vectorize() has a serious side effect: the dtype of an array
returned by a vectorized function depends on which vectorized function was
called first!
This creates bugs that are hard to detect, because such a behavior is
highly unusual.
I had understood from the documentation of vectorize(f) that the type of
the first value returned by '''f''' instead determined the dtype of the
returned array…
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1487>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list