【发布时间】:2017-03-13 08:40:40
【问题描述】:
我想连接两个形状为(100,3) and (100,7) 的numpy 数组以获得(100,10) 矩阵。
我尝试过使用hstack, concatenate,但只收到ValueError: all the int arrays must have same number of dimensions
在像下面这样的虚拟示例中,它可以工作...
x=np.arange(30).reshape(10,3)
y=np.arange(20).reshape(10,2)
np.concatenate((x,y), axis=1)
更新 1:
我使用 sklearn 的预处理模块(RobustScaler 和 OneHotEncoder)创建了前两个指标。
更新 2:
当使用 scipy.sparse.hstack 时它可以工作,但是为什么
【问题讨论】:
-
您能否用有关原始阵列的更多信息更新您的问题?
-
与 hstack 一起使用:
np.hstack([x, y])。你确定x和y的形状兼容吗? -
@kennytm,我有 print(x.shape, y.shape) 给出 (100,3) (100,7) 错误消息“所有输入...” - 回溯从堆栈返回 _nx.concatenate(arrs,1)
-
@Roby
_nx是什么?arrs是什么?np.concatenate((x, y), axis=1)也适合我。 -
@kennytm 那是 numpy/core/shape_base.py 的回溯——当使用辣味.sparse.hstack 时它可以工作——但为什么?
标签: python arrays numpy concatenation