'numpy.ndarray' object has no attribute 'index'
时间: 2023-09-13 15:03:27 浏览: 75
Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
5星 · 资源好评率100%
The error message `'numpy.ndarray' object has no attribute 'index'` typically occurs when you try to call the `index()` method on a NumPy array. However, unlike lists in Python, NumPy arrays don't have an `index()` method.
To find the index of an element in a NumPy array, you can use the `numpy.where()` function. Here's an example:
```python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
idx = np.where(arr == 3)
print(idx)
```
This will output `(array([2]),)`, which indicates that the value `3` is located at index `2` in the array.
阅读全文