NumPystack函数
此函数沿新轴连接数组序列。自NumPy 1.10.0版本以来已添加此功能。需要提供以下参数。
numpy.stack(arrays, axis)
哪里,
| Sr.No. | Parameter & 描述 |
|---|---|
| 1 |
arrays 相同维度的数组序列 |
| 2 |
axis 输入数组沿其堆叠的输出数组中的轴 |
import numpy as np a = np.array([[1,2],[3,4]]) print 'First Array:' print a print '\n' b = np.array([[5,6],[7,8]]) print 'Second Array:' print b print '\n' print 'Stack the two arrays along axis 0:' print np.stack((a,b),0) print '\n' print 'Stack the two arrays along axis 1:' print np.stack((a,b),1)
它应该产生以下输出-
First array: [[1 2] [3 4]] Second array: [[5 6] [7 8]] Stack the two arrays along axis 0: [[[1 2] [3 4]] [[5 6] [7 8]]] Stack the two arrays along axis 1: [[[1 2] [5 6]] [[3 4] [7 8]]]
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者