此函数沿新轴连接数组序列。自NumPy 1.10.0版本以来已添加此功能。需要提供以下参数。
注意-此功能在版本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]]]
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)