numpy - 如何连接具有不同尺寸(形状)的ndrarray?
问题描述
我有两个数据类型是 ndarray。我想合并 X_train 和 Y_train,但它们的形状不同。我尝试使用连接,堆栈,但它显示了同样的错误。
print(X_train.shape)
print(type(X_train[1]))
print(Y_train.shape)
print(type(Y_train[1]))
(17731, 30, 14, 1)
<class 'numpy.ndarray'>
(17731, 1)
<class 'numpy.ndarray'>
x_train_tt = np.stack([X_train , Y_train])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-43-74b8e20eca7c> in <module>
----> 3 x_train_tt = np.stack([X_train , Y_train])
<__array_function__ internals> in stack(*args, **kwargs)
~\anaconda3\envs\newenvironment2.3.6\lib\site-packages\numpy\core\shape_base.py in stack(arrays, axis, out)
424 shapes = {arr.shape for arr in arrays}
425 if len(shapes) != 1:
--> 426 raise ValueError('all input arrays must have the same shape')
427
428 result_ndim = arrays[0].ndim + 1
ValueError: all input arrays must have the same shape
有什么解决办法吗?
我想拥有这样的身材
x_train_tt.shape (17731,30,15,1)
解决方案
推荐阅读
- python - 绘图显示 Jupyter 中的错误点
- macos - 替换字符applescript时出错
- quantum-computing - Hadamarding 的目的是什么,然后在传送期间测量消息?
- r - R:条形图宽度不一致
- python - Numba 索引错误:TypeError: Can't index at [0] in i8*
- html - 什么是html 以及它如何有用?
- sql - 我在 SQL 表中有一种格式的数据,现在我想将其插入到另一个表中,但格式不同
- android-studio - 我对 android studio 中的评论字体有疑问
- office-js - 如何从 Outlook JS 加载项创建和发送会议电子邮件和邀请?
- python - 这是访问与 Python 脚本相邻/打包的数据的认可方式吗?