numpy中sum(axis=0)和axis=1的计算原理
看起来挺简单的样子,但是在给sum函数中加入参数。sum(a,axis=0)或者是.sum(axis=1) 就有点不解了
在我实验以后发现 我们平时用的sum应该是默认的axis=0 就是普通的相加
而当加入axis=1以后就是将一个矩阵的每一行向量相加
例如:
import numpy as np
np.sum([[0,1,2],[2,1,3],axis=1)
结果就是:array([3,6])
下面是自己的实验结果,与上面的说明有些不符:
a = np.array([[0, 2, 1]])
print a.sum()
print a.sum(axis=0)
print a.sum(axis=1)
结果分别是:3, [0 1 2], [3]
b = np.array([0, 2, 1])
print b.sum()
print b.sum(axis=0)
print b.sum(axis=1)
结果分别是:3, 3, 运行错误:'axis' entry is out of bounds
可知:对一维数组,只有第0轴,没有第1轴
c = np.array([[0, 2, 1], [3, 5, 6], [0, 1, 1]])
print c.sum()
print c.sum(axis=0)
print c.sum(axis=1)
结果分别是:19, [3 8 8], [ 3 14 2]

numpy中sum(axis=0)和axis=1的计算原理的更多相关文章
- 【python】详解numpy库与pandas库axis=0,axis= 1轴的用法
对数据进行操作时,经常需要在横轴方向或者数轴方向对数据进行操作,这时需要设定参数axis的值: axis = 0 代表对横轴操作,也就是第0轴: axis = 1 代表对纵轴操作,也就是第1轴: nu ...
- Python之NumPy(axis=0 与axis=1)区分
转自:http://blog.csdn.net/wangying19911991/article/details/73928172 https://www.zhihu.com/question/589 ...
- python numpy中sum()时出现负值
import numpy a=numpy.random.randint(1, 4095, (5000,5000)) a.sum() 结果为负值, 这是错误的,a.sum()的类型为 int32,如何做 ...
- python和numpy中sum()函数的异同
转载:https://blog.csdn.net/amuchena/article/details/89060798和https://www.runoob.com/python/python-func ...
- Python数据分析中 DataFrame axis=0与axis=1的理解
python中的axis究竟是如何定义的呢?他们究竟代表是DataFrame的行还是列? 直接上代码people=DataFrame(np.random.randn(5,5), columns=['a ...
- Python之NumPy(axis=0/1/2...)的透彻理解
https://blog.csdn.net/sky_kkk/article/details/79725646 numpy中axis取值的说明首先对numpy中axis取值进行说明:一维数组时axis= ...
- 关于NumPy中数组轴的理解
参考原文链接(英文版):https://www.sharpsightlabs.com/blog/numpy-axes-explained/:中文版:https://www.jianshu.com/p/ ...
- numpy中stack、hstack,vstack,dstack函数功能解释
https://blog.csdn.net/Riverhope/article/details/78922006 https://blog.csdn.net/ygys1234/article/deta ...
- 【python】Numpy中stack(),hstack(),vstack()函数详解
转自 https://blog.csdn.net/csdn15698845876/article/details/73380803 这三个函数有些相似性,都是堆叠数组,里面最难理解的应该就是stack ...
随机推荐
- [NetworkFlow]网络流建模相关
流 网络流问题本质上是线性规划问题的应用之中的一个,线性规划问题的标准形式是给出一组等式约束和不等式约束.要求最优化一个线性函数. 在流问题中,变量以流量的形式出如今问题中,我们给出一个流网络(以有向 ...
- Android Back键和Home键的区别
back键 Android的程序无需刻意的去退出,当你一按下手机的back键的时候,系统会默认调用程序栈中最上层Activity的Destroy()方法来,销毁当前Activity.当此Activit ...
- linux sed 命令,sed -i
-i 参数 :直接在原文件上进行操作整条语句意思是将b.c文件里第一个匹配printa替换为printb
- hdu 2205(容斥原理)
Eddy's爱好 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdoj-1896 stones
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- 批量梯度下降(Batch gradient descent) C++
At each step the weight vector is moved in the direction of the greatest rate of decrease of the err ...
- git强制放弃本地更改
git fetch --allgit reset --hard origin/master origin是服务器上的本地仓库master是分支
- lsit集合去重复 顶级表达式
updateList = updateList.Where((x, i) => updateList.FindIndex(z => z.ID == x.ID) == i).ToList() ...
- 6.10---mybatis的实体---接口---接口映射---主配置文件
- Django中关于MySQL的bug总结
bug one: You are trying to add a non-nullable field 'height' to person without a default; we can't d ...