Python's sum vs. NumPy's numpy.sum

前端 未结 6 952
时光说笑
时光说笑 2020-11-28 08:03

What are the differences in performance and behavior between using Python\'s native sum function and NumPy\'s numpy.sum? sum works on

6条回答
  •  温柔的废话
    2020-11-28 08:22

    if you use sum(), then it gives

    a = np.arange(6).reshape(2, 3)
    print(a)
    print(sum(a))
    print(sum(sum(a)))
    print(np.sum(a))
    
    
    >>>
    [[0 1 2]
     [3 4 5]]
    [3 5 7]
    15
    15
    

提交回复
热议问题