[Numpy-discussion] TypeError when using double , longdouble in numpy.dot

Christoph Gohlke cgohlke@uci....
Thu Jul 8 02:27:55 CDT 2010



On 7/7/2010 9:59 PM, Charles R Harris wrote:
>
>
> On Wed, Jul 7, 2010 at 10:13 PM, Christoph Gohlke <cgohlke@uci.edu
> <mailto:cgohlke@uci.edu>> wrote:
>
>     Dear NumPy developers,
>
>     I am trying to solve some scipy.sparse TypeError failures reported in
>     [1] and reduced them to the following example:
>
>
>     > >> import numpy
>     > >> a = numpy.array([[1]])
>
>     > >> numpy.dot(a.astype('single'), a.astype('longdouble'))
>     array([[1.0]], dtype=float64)
>
>     > >> numpy.dot(a.astype('double'), a.astype('longdouble'))
>     Traceback (most recent call last):
>        File "<stdin>", line 1, in <module>
>     TypeError: array cannot be safely cast to required type
>
>
> Just for laughs, what happens if you reverse the order of the arguments?
> Type promotion in numpy is not always symmetric.
>

This works as expected:

>>> numpy.dot(a.astype('longdouble'), a.astype('double'))
array([[1.0]], dtype=float64)

--
Christoph


More information about the NumPy-Discussion mailing list