问题描述
我有一个数字识别的 CNN 项目。我正在 colab 中尝试它。我有一个 784 像素的一维向量,在将它传递给 CNN 之前,我必须将其重塑为 (28x28x1)。但我无法重塑它。我有一个错误。 这是我的代码-
x_train = x_train.reshape(-1,28,1)
x_test = x_test.reshape(-1,1)
test_df=test_df.reshape(-1,1)
我得到了错误,它是 -
AttributeError Traceback (most recent call last)
<ipython-input-31-fc5920daac40> in <module>()
9 # reshape(examples,height,width,channels)
10 x_train = x_train.reshape(-1,1)
---> 11 x_test = x_test.reshape(-1,1)
12 test_df=test_df.reshape(-1,1)
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in __getattr__(self,name)
5139 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5140 return self[name]
-> 5141 return object.__getattribute__(self,name)
5142
5143 def __setattr__(self,name: str,value) -> None:
AttributeError: 'DataFrame' object has no attribute 'reshape'
我阅读了 this question 并且当我使用此代码时-
x_train = x_train.values.reshape(-1,1)
x_test = x_test.values.reshape(-1,1)
test_df=test_df.values.reshape(-1,1)
我也有错误,它是 -
AttributeError Traceback (most recent call last)
<ipython-input-32-93a2a0b4627a> in <module>()
8 ##first param in reshape is number of examples. We can pass -1 here as we want numpy to figure that out by itself ###################
9 # reshape(examples,channels)
---> 10 x_train = x_train.values.reshape(-1,1)
11 x_test = x_test.values.reshape(-1,1)
12 test_df=test_df.values.reshape(-1,1)
AttributeError: 'numpy.ndarray' object has no attribute 'values'
有时它会出错,有时它会运行。我不知道问题出在哪里,我该怎么办?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)