Python numpy.square vs **

前端 未结 2 1243
灰色年华
灰色年华 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:20

    You can check the execution time to get clear picture of it

    In [2]: import numpy as np
    In [3]: A = np.array([[2, 2],[2, 2]])
    In [7]: %timeit np.square(A)
    1000000 loops, best of 3: 923 ns per loop
    In [8]: %timeit A ** 2
    1000000 loops, best of 3: 668 ns per loop
    

提交回复
热议问题