Numpy concatenate 函数用法

numpy.concatenate((a1, a2, …), axis=0)
Join a sequence of arrays along an existing axis.(按轴axis连接array组成一个新的array)
The arrays must have the same shape, except in the dimension corresponding to axis
axis:default is 0

示例代码:
Numpy 二维和一维的区别

>>> b = np.array([[5,6]])         b是二维的
>>> b.shape
(1, 2)
>>> b = np.array([5,6])                 b是一维的
>>> b.shape
(2,)
>>> a = np.array([[1, 2], [3, 4]])
>>> b = np.array([[5, 6]])               b是一个二维array,b.shape为(1,2>>> np.concatenate((a, b), axis=0)
array([[1, 2],
       [3, 4],
       [5, 6]])
>>> np.concatenate((a, b.T), axis=1)    b.T是一个二维array,其shape为(2,1)
array([[1, 2, 5],
       [3, 4, 6]])

一维array时,所有数字相连接

>>> a=np.array([1,2,3])
>>> b=np.array([11,22,33])
>>> c=np.array([44,55,66])
>>> np.concatenate((a,b,c),axis=0)  
array([ 1,  2,  3, 11, 22, 33, 44, 55, 66])

推广至多维
例如4维,a.shape为(4,5,6,10),b.shape为(4,5,6,20)

np.concatenate([a,b], axis=3) # 返回张量的shape为(4,5,6,30)

参考:
[1] https://www.cnblogs.com/ymjyqsx/p/6472507.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值