concatenate
优质
小牛编辑
142浏览
2023-12-01
连接是指加入。 此函数用于沿指定轴连接两个或多个相同形状的数组。 该函数采用以下参数。
numpy.concatenate((a1, a2, ...), axis)
Where,
Sr.No. | 参数和描述 |
---|---|
1 | a1,a2.. 相同类型的数组序列 |
2 | axis 必须连接数组的轴。 默认值为0 |
例子 (Example)
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'
# both the arrays are of same dimensions
print 'Joining the two arrays along axis 0:'
print np.concatenate((a,b))
print '\n'
print 'Joining the two arrays along axis 1:'
print np.concatenate((a,b),axis = 1)
其输出如下 -
First array:
[[1 2]
[3 4]]
Second array:
[[5 6]
[7 8]]
Joining the two arrays along axis 0:
[[1 2]
[3 4]
[5 6]
[7 8]]
Joining the two arrays along axis 1:
[[1 2 5 6]
[3 4 7 8]]