python - 将不同维度的数组 append 到单个数组

标签 python arrays numpy append

我有三个向量(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/

相关文章:

javascript - 在 Javascript 中从 JSON 数组中查找名称值对的有效方法

numpy - numpy.dtype 对应的 ctypes 类型?

python - 如何在子 shell 中激活 conda env?

python - tf.train.shuffle_batch_join 和 tf.train.shuffle_batch 之间的区别

c - C 中的指针和索引 - 出了什么问题?

沿轴的 Numpy 最大值

Python + NumPy : TypeError: 'int' object is not callable

python - 如何从 Python 中的所有行和列数组中找到单个最大值并显示其行和列索引

python - 在 Google App Engine 应用程序中过滤 GMail 邮件

javascript - JavaScript 中的类型化数组不是数组