np.argsort()
时间: 2023-09-09 22:10:07 浏览: 82
The `numpy.argsort()` function returns an array of indices that would sort an input array in ascending order.
Syntax:
`numpy.argsort(a, axis=-1, kind=None, order=None)`
Parameters:
- `a`: Input array to be sorted.
- `axis`: Axis along which to sort. If None, the array is flattened before sorting. Default is -1.
- `kind`: Sorting algorithm. Default is 'quicksort'.
- `order`: If `a` is structured array, the field to use for sorting. Default is None.
Returns:
- An array of indices that would sort the input array in ascending order.
Example:
```
import numpy as np
arr = np.array([9, 3, 7, 1, 2, 6, 8, 5, 4])
sorted_indices = np.argsort(arr)
print(sorted_indices)
```
Output:
```
[3 4 1 8 7 5 2 6 0]
```
阅读全文