numpy: Invalid value encountered in true_divide

前端 未结 2 1514
礼貌的吻别
礼貌的吻别 2021-02-18 15:34

I have two numpy arrays and I am trying to divide one with the other and at the same time, I want to make sure that the entries where the divisor is 0, should just be replaced w

相关标签:
2条回答
  • 2021-02-18 15:54

    You may have a NAN, INF, or NINF floating around somewhere. Try this:

    np.isfinite(diff_images).all()
    np.isfinite(b_0).all()
    

    If one or both of those returns False, that's likely the cause of the runtime error.

    0 讨论(0)
  • 2021-02-18 16:03

    Another useful Numpy command is nan_to_num(diff_images) By default it replaces in a Numpy array; NaN to zero, -INF to -(large number) and +INF to +(large number)

    You can change the defaults, see https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html

    0 讨论(0)
提交回复
热议问题