numpy.ndarray' object has no attribute 'iloc
时间: 2023-09-25 16:15:38 浏览: 147
numpy.meshgrid()理解(小结)
5星 · 资源好评率100%
The 'iloc' method is not available for numpy arrays as it is a method of pandas DataFrames and Series. The 'iloc' method is used to select rows and columns based on their integer position.
If you want to select specific rows or columns from a numpy array, you can use indexing or slicing. For example, to select the first row of a 2D numpy array, you can use:
```
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
first_row = arr[0]
```
This will return the first row of the array `[1, 2, 3]`. Similarly, to select the first column, you can use:
```
first_column = arr[:, 0]
```
This will return the first column of the array `[1, 4, 7]`.
阅读全文