gpt4 book ai didi

python - 将输入添加到 numpy 3d 数组

转载 作者:行者123 更新时间:2023-11-30 09:48:26 31 4
gpt4 key购买 nike

我有一个 pandas DataFrame,我将其转换为这样的 numpy 数组

  training_set = dataset_train.iloc[:, 1:2].values

X_train = []
for i in range(60, 1258):
X_train.append(training_set[i-60:i, 0])
y_train.append(training_set[i, 0])

X1_train = np.array(X1_train)

X1_train.shape = (1198, 60)

创建 3d 数组后

X1_train = np.reshape(X1_train, (X1_train.shape[0], X1_train.shape[1] , 1))

X2_train.shape = (1198,0)

现在,当尝试在我的数组中添加新输入 x2_train.shape[0], x2_train.shape[1] 时,我被阻止了

我尝试了一些类似的事情

X1_train = np.reshape(X1_train, ([X1_train.shape[0], X1_train.shape[1], X2_train.shape[0], X2_train.shape[1]] , 1))

X1_train = np.reshape(X1_train, (X2_train.shape[0], X2_train.shape[1] , 1))

运行我的代码时出现此错误

File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 257, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)

File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 62, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)

File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 42, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)

TypeError: 'list' object cannot be interpreted as an integer

numpy doc不是很清楚

最佳答案

你的 react 很好,但你没有忘记 reshape 你的数组

你可以删除这个

  X1_train = np.reshape(X1_train, (X1_train.shape[0], X1_train.shape[1] , 1))

X2_train = np.reshape(X2_train, (X2_train.shape[0], X2_train.shape[1] , 1))


new_train = np.dstack((X1_train, X2_train))

然后像这样编写代码

new_train  = np.dstack((X1_train, X2_train))

关于python - 将输入添加到 numpy 3d 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49212114/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com