Python 无法连接两个numpy数组

Python 无法连接两个numpy数组,python,numpy,Python,Numpy,给定两个numpy数组a1和a2: >>>np.shape(a1) (4465, 5000) >>>np.shape(a2) (4465, ) 但是, >>>np.concatenate((a1, a2), axis=1) ValueError: all the input arrays must have the same number of dimensions 我也试过: np.concatenate((a1, a2), axis=

给定两个numpy数组
a1
a2

>>>np.shape(a1)
(4465, 5000)
>>>np.shape(a2)
(4465, )
但是,

>>>np.concatenate((a1, a2), axis=1)
ValueError: all the input arrays must have the same number of dimensions
我也试过:

np.concatenate((a1, a2), axis=1),
np.concatenate((a1, a2.T), axis=0),
np.concatenate((a1, a2.T), axis=1)
但也有同样的错误


你能告诉我我的密码有什么问题吗?谢谢

如错误消息所述,
a1
a2
的维度数不相同(可通过属性
ndims
访问)。使用
a2=a2[:,无]
使
a2成为二维。您还可以使用更显式的语法
a2=a2[:,np.newaxis]
,但它严格等效

你期望什么样的产出?长度为4465×5001的数组?@EdSmith是的!我就是这么想的want@Alex完全不同。我没有弄丢括号。只需删除重复项。
a2=a2[:,np.newaxis]
有效,但
a2=a2[:,None]
无效。为什么?奇怪,您使用的是哪个版本的python/numpy?您也可以使用
a2=np.expand_dims(a2,1)
a2=np?在这两种情况下,都包括它们