Numpy: 仅能将整数标量数组转换为标量索引

以下是代码:

我得到了以下错误:

Traceback (most recent call last): File”/Users/evgenypavlov/Documents/ml_tutorial_1/main.py”, line 34, inx_train = np.reshape(x_train, (x_train.shape[0], x_train[1], 1)) File “<array_function internals>”, line 5, in reshape File”/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/fromnumeric.py”,line 299, in reshapereturn _wrapfunc(a, ‘reshape’, newshape, order=order) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/fromnumeric.py”,line 67, in _wrapfuncreturn _wrapit(obj, method, *args, **kwds) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/fromnumeric.py”,line 44, in _wrapitresult = getattr(asarray(obj), method)(*args, **kwds) TypeError: only integer scalar arrays can be converted to a scalar index

据我所知,我已经将其转换为np.array,那么是什么导致了这个问题,又该如何解决呢?


回答:

您在元组的第二个元素中缺少了shape:

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

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注