Numpy Cannot cast ufunc multiply output from dtype

后端 未结 3 1634
無奈伤痛
無奈伤痛 2021-01-01 14:45

I\'d like to multiply an int16 array but a float array, with auto rounding, but this fails :

import numpy

A = numpy.array([1, 2, 3         


        
3条回答
  •  独厮守ぢ
    2021-01-01 15:40

    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')
    

提交回复
热议问题