'list' object has no attribute 'squeeze'
时间: 2023-09-24 22:06:16 浏览: 414
python报错: 'list' object has no attribute 'shape'的解决
5星 · 资源好评率100%
This error message usually occurs when you try to use the `.squeeze()` method on a Python list object. The `.squeeze()` method is a NumPy function that removes single-dimensional entries from an array.
To fix this error, you need to make sure you are calling the method on a NumPy array object, not a Python list object. If you are working with a list, you can convert it to a NumPy array using the `numpy.array()` function.
For example:
```
import numpy as np
my_list = [1, 2, 3, 4, 5]
my_array = np.array(my_list)
# Now you can use the squeeze() method on my_array
my_squeezed_array = my_array.squeeze()
```
阅读全文