NumPy 数组操作 numpy.concatenate

NumPy 数组操作 numpy.concatenate

连接是指连接的意思。该函数用于沿指定轴将两个或多个具有相同形状的数组连接起来。该函数接受以下参数。

numpy.concatenate((a1, a2, ...), axis)

在哪里

序号 参数与描述
1 a1,a2.. 同类型数组的序列
2 axis 数组要连接的轴。默认为0

示例

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]]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程