NumPy 中的 concatenate函数

首页 / Numpy入门教程 / NumPy 中的 concatenate函数

串联是指连接,此函数用于沿指定轴连接两个或多个相同维度的数组。该函数采用以下参数。

numpy.concatenate((a1, a2, ...), axis)
Sr.No. Parameter & 描述
1

a1,a2 ..

相同类型的数组序列

2

axis

必须沿其连接数组的轴。默认为0

链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-concatenate.html

来源:LearnFk无涯教程网

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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

朱赟的技术管理课 -〔朱赟〕

Go语言核心36讲 -〔郝林〕

许式伟的架构课 -〔许式伟〕

浏览器工作原理与实践 -〔李兵〕

动态规划面试宝典 -〔卢誉声〕

性能优化高手课 -〔尉刚强〕

说透5G -〔杨四昌〕

云原生架构与GitOps实战 -〔王炜〕

结构会议力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)