以下是代码:
我得到了以下错误:
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))