NoneType' object has no attribute 'shape
时间: 2023-09-15 21:20:57 浏览: 146
This error message typically occurs when you try to access the shape attribute of a variable that is NoneType. In other words, the variable does not have a shape because it does not contain any data.
To fix this error, you should check that the variable is not None before trying to access its shape attribute. You can do this using an if statement or by using the isinstance() function to check the variable's type. Here's an example:
```
import numpy as np
# Create a variable that is None
my_var = None
# Check if my_var is not None before accessing its shape attribute
if my_var is not None:
print(my_var.shape)
else:
print("my_var is None")
# Output: my_var is None
```
In this example, we first create a variable my_var that is None. We then check if my_var is not None before trying to print its shape attribute. Since my_var is None, we print a message indicating that the variable is None.
阅读全文
相关推荐


















