import numpy as np
a=np.array([[1,2],[3,4]])
b=np.array([[5,6],[7,8]])
print(“a,b数组的点乘结果:\n”,ab)
print(“sum函数对于2-n数组:”)
print(sum(ab))
print(“sum函数对于一维数组:”)
print(sum(sum(a*b)))
print(“numpy中的vdot函数:\n”,np.vdot(a,b))
c=np.arange(8).reshape(2,2,2)
print(“自带sum函数对于3-n数组:”)
print(sum©)
结果如下:
sum函数总是沿着dimension 0来求和的