[NumPy-Tickets] [NumPy] #1890: piecewise throws TypeError for int input and sin
NumPy Trac
numpy-tickets@scipy....
Fri Jul 1 18:34:00 CDT 2011
#1890: piecewise throws TypeError for int input and sin
--------------------+-------------------------------------------------------
Reporter: deil | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: Other | Version: 1.6.0
Keywords: |
--------------------+-------------------------------------------------------
Comment(by deil):
Replying to [comment:2 charris]:
> If you truly want integer output, then you should use
np.sin(x).astype(x.dtype).
I want float output, I now use this, which works fine:
{{{
>>> np.piecewise(x.astype(float), [x < 5, x >= 5], [lambda x: -x, lambda
x: np.sin(x)])
}}}
I didn't know that numpy automatically casts if the rhs is a list, but not
if it is an array:
{{{
a = np.zeros(10, dtype=int)
a[[1,4]] = [1.1, 4] # Casts to int
a[[1,4]] = np.array([1.1, 4]) # TypeError
}}}
I imagine there are good reasons for not automatically casting the array,
but throwing a TypeError?!
I just had never run into this 'problem' of having to cast myself and
couldn't figure out why piecewise was throwing the error.
Btw., this is the second ticket I filed for numpy which turned out to be
missing understanding on my part.
In the future, should I ask on the mailing list instead?
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1890#comment:3>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list