What is the difference between np.sum and np.add.reduce?

前端 未结 2 1781
挽巷
挽巷 2020-12-30 23:22

What is the difference between np.sum and np.add.reduce?
While the docs are quite explicit:

For example, add.reduce()

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 23:42

    There is actually one difference that might bite you if you were to blindly refactor from one to the other:

    >>> import numpy as np
    >>> a = np.arange(4).reshape(2, 2)
    >>> 
    >>> np.sum(a)
    6
    >>> np.add.reduce(a)
    array([2, 4])
    >>> 
    

    The axis default values are different!

提交回复
热议问题