Traceback (most recent call last): File "D:\PyCharm\learning\1\11.py", line 167, in <module> n.train(train_input,train_output) File "D:\PyCharm\learning\1\11.py", line 143, in train error = error + self.errorbackpropagate(targets, lr, m) File "D:\PyCharm\learning\1\11.py", line 100, in errorbackpropagate error = (1 / 2) * np.dot((targets.reshape(-1, 1) - self.active_out).T, AttributeError: 'list' object has no attribute 'reshape'
时间: 2024-04-16 07:29:30 浏览: 19
根据错误信息,出现了`AttributeError: 'list' object has no attribute 'reshape'`的异常。这个错误通常发生在尝试对不支持`reshape`方法的对象进行调用时。
根据你提供的错误信息,异常发生在以下代码段中:
```python
error = (1 / 2) * np.dot((targets.reshape(-1, 1) - self.active_out).T, ...
```
根据错误信息,可能是因为`targets`是一个列表对象,而不是一个NumPy数组或矩阵。在这种情况下,尝试对列表对象调用`reshape`方法会导致`AttributeError`异常。
要解决这个问题,你可以将`targets`转换为NumPy数组或矩阵,然后再进行操作。你可以使用`np.array()`或`np.asarray()`函数来将列表转换为NumPy数组。
例如,将`targets`转换为NumPy数组的代码如下:
```python
targets = np.array(targets)
```
然后,你可以继续使用`reshape`方法来调整数组的形状。
请尝试修改你的代码,并确保将`targets`转换为NumPy数组或矩阵后再进行相关操作。如果问题仍然存在,请提供更多相关的代码和上下文信息,以便我能够提供更准确的帮助。
相关问题
Traceback (most recent call last): File "D:\PyCharm\learning\1\11.py", line 159, in <module> n.train(train_input,train_output) File "D:\PyCharm\learning\1\11.py", line 135, in train for j in self.num_input: TypeError: 'int' object is not iterable
根据你提供的错误信息,出现了一个类型错误:`TypeError: 'int' object is not iterable`。这个错误通常发生在你尝试对一个整数对象进行迭代操作时。
根据你提供的代码片段,错误发生在`for j in self.num_input:`这行代码上。`self.num_input`是一个整数,而不是一个可迭代的对象(如列表、元组等)。因此,你不能使用`for`循环对其进行迭代操作。
如果你想要迭代某个范围内的整数,你可以使用`range()`函数来生成一个整数序列,然后进行迭代。例如:
```python
for j in range(self.num_input):
# 在这里执行迭代操作
```
请确保将代码中的`for j in self.num_input:`替换为上述示例代码,以解决这个类型错误。如果问题仍然存在,请提供更多相关的代码和上下文信息,以便我能够提供更准确的帮助。
D:\anaconda\envs\mytest\python.exe D:/PyCharm/learning/1/11.py Traceback (most recent call last): File "D:\PyCharm\learning\1\11.py", line 158, in <module> n.train(train_input) File "D:\PyCharm\learning\1\11.py", line 135, in train inputs = j[0:self.num_in - 1] TypeError: 'float' object is not subscriptable
这个错误是因为你试图对一个浮点数对象进行下标操作,但是浮点数对象是不可被下标的。根据你提供的代码,错误发生在第135行,这行代码尝试对一个名为`j`的浮点数对象进行下标操作。可能是在这之前的代码逻辑有问题,导致`j`被赋值为一个浮点数。你可以检查一下第135行之前的代码,看看是否有地方将`j`赋值为了一个浮点数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)