RuntimeWarning: Divide by Zero error: How to avoid? PYTHON, NUMPY

前端 未结 5 1629
遇见更好的自我
遇见更好的自我 2020-12-10 08:10

I am running in to RuntimeWarning: Invalid value encountered in divide

 import numpy
 a = numpy.random.rand((1000000, 100))
 b = numpy.random.rand((1,100))
          


        
5条回答
  •  鱼传尺愫
    2020-12-10 08:31

    You can use np.where( condition ) to perform a conditional slice of where norms does not equal 0 before dividing:

    norms = np.where(norms != 0 ) 
    angles = dots/norms
    

提交回复
热议问题