1. python 自己的sum() 输入的参数首先是[] - >>> sum([0,1,2])
- 3
- >>> sum([0,1,2],3)
- 6
- >>> sum([0,1,2],[3,2,1])
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: can only concatenate list (not "int") to list
2.python的 numpy当中 现在对于数据的处理更多的还是numpy。没有axis参数表示全部相加,axis=0表示按列相加,axis=1表示按照行的方向相加 - >>> import numpy as np
- >>> a=np.sum([[0,1,2],[2,1,3]])
- >>> a
- 9
- >>> a.shape
- ()
- >>> a=np.sum([[0,1,2],[2,1,3]],axis=0)
- >>> a
- array([2, 2, 5])
- >>> a.shape
- (3,)
- >>> a=np.sum([[0,1,2],[2,1,3]],axis=1)
- >>> a
- array([3, 6])
- >>> a.shape
- (2,)
|