栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

多维NumPy数组中的轴[重复]

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

多维NumPy数组中的轴[重复]

最简单的方法是使用示例:

In [8]: x = np.array([[1, 2, 3], [4,5,6],[7,8,9]], np.int32)In [9]: xOut[9]: array([[1, 2, 3],       [4, 5, 6],       [7, 8, 9]], dtype=int32)In [10]: x.sum(axis=0)  # sum the columns [1,4,7] = 12, [2,5,8] = 15 [3,6,9] = 18  Out[10]: array([12, 15, 18])In [11]: x.sum(axis=1)    # sum the rows [1,2,3] = 6, [4,5,6] = 15 [7,8,9] = 24Out[11]: array([ 6, 15, 24])

轴0轴1

在三维数组中:

In [26]: x = np.array((((1,2), (3,4) ), ((5,6),(7,8))))In [27]: xOut[27]:    array([[[1, 2],[3, 4]],          [[5, 6],[7, 8]]])In [28]: x.shape # dimensions of the arrayOut[28]: (2, 2, 2)In [29]: x.sum(axis=0)Out[29]: array([[ 6,  8],   #  [1,5] = 6 [2,6] = 8 [3,7] = 10 [4, 8] = 12      [10, 12]])In [31]: x.sum(axis=1)Out[31]:     array([[ 4,  6],   # [1,3] = 4 [2,4] = 6 [5, 7] = 12 [6, 8] = 14[12, 14]])In [33]: x.sum(axis=2) # [1, 2] = 3 [3, 4] = 7 [5, 6] = 11 [7, 8] = 15Out[33]: array([[ 3,  7],       [11, 15]])In [77]: x.ndim # number of dimensions of the arrayOut[77]: 3

链接以获取有关使用多维数据数组的良好教程



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668145.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号