Python numpy.square vs **

前端 未结 2 1277
灰色年华
灰色年华 2021-02-05 02:43

Is there a difference between numpy.square and using the ** operator on a Numpy array?

From what I can see it yields the same result.

2条回答
  •  花落未央
    2021-02-05 03:39

    For most appliances, both will give you the same results. Generally the standard pythonic a*a or a**2 is faster than the numpy.square() or numpy.pow(), but the numpy functions are often more flexible and precise. If you do calculations that need to be very accurate, stick to numpy and probably even use other datatypes float96.

    For normal usage a**2 will do a good job and way faster job than numpy. The guys in this thread gave some good examples to a similar questions.

提交回复
热议问题