我有三个向量(numpy 数组),向量_1、向量_2、向量_3
如下:
维度(向量1)=(200,2048)
维度(向量2)=(200,8192)
维度(向量3)=(200,32768)
我想 append 这些向量以获得vector_4:
维度(向量4)= (200,2048+8192+32768)= (200, 43008)
分别添加向量1、向量2、向量3
我尝试以下操作:
vector4=numpy.concatenate((vector1,vector2,vector3),axis=0)
ValueError: all the input array dimensions except for the concatenation axis must match exactly
和
vector4=numpy.append(vector4,[vector1,vector2,vectors3],axis=0)
TypeError: append() missing 1 required positional argument: 'values'
最佳答案
我相信您正在寻找numpy.hstack
。
>>> import numpy as np
>>> a = np.arange(4).reshape(2,2)
>>> b = np.arange(6).reshape(2,3)
>>> c = np.arange(8).reshape(2,4)
>>> a
array([[0, 1],
[2, 3]])
>>> b
array([[0, 1, 2],
[3, 4, 5]])
>>> c
array([[0, 1, 2, 3],
[4, 5, 6, 7]])
>>> np.hstack((a,b,c))
array([[0, 1, 0, 1, 2, 0, 1, 2, 3],
[2, 3, 3, 4, 5, 4, 5, 6, 7]])
关于python - 将不同维度的数组 append 到单个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47516286/