NumPy ndarray.all() vs np.all(ndarray) vs all(ndarray)

前端 未结 3 1692
夕颜
夕颜 2021-02-20 17:06

What is the the difference between the three \"all\" methods in Python/NumPy? What is the reason for the performance difference? Is it true that ndarray.all() is always the fast

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 17:21

    I'll take a swing at this

    • np.all is a generic function which will work with different data types, under the hood this probably looks for ndarray.all which is why it's slightly slower.

    • all is a python bulit-in function see https://docs.python.org/2/library/functions.html#all.

    • ndarray.all is method of the 'numpy.ndarray' object, calling this directly may be faster.

提交回复
热议问题