Numpy Cannot cast ufunc multiply output from dtype Numpy Cannot cast ufunc multiply output from dtype arrays arrays

Numpy Cannot cast ufunc multiply output from dtype


2 ways to solve this:

You can solve this by replacing

A *= B

with

A = (A * B)

or with

numpy.multiply(A, B, out=A, casting='unsafe')


You could use broadcasting to multiply the two arrays and take only the integer part as follows:

In [2]: (A*B).astype(int)Out[2]: array([ 0,  4,  9, 16])

Timing Constraints:

In [8]: %timeit (A*B).astype(int)1000000 loops, best of 3: 1.65 µs per loopIn [9]: %timeit np.multiply(A, B, out=A, casting='unsafe')100000 loops, best of 3: 2.01 µs per loop


import numpy as npA = np.float_(A)A *= B

try this. I think are different array type you get fail.

Cast