return the indices and values of the n_instances highest values. Args: values: Contains the values to be selected from. n_instances: Specifies how many indices and values to return. Returns: The indices and values of the n_instances largest values.
(values: np.ndarray, n_instances: int = 1)
| 53 | |
| 54 | |
| 55 | def multi_argmax(values: np.ndarray, n_instances: int = 1) -> np.ndarray: |
| 56 | """ |
| 57 | return the indices and values of the n_instances highest values. |
| 58 | |
| 59 | Args: |
| 60 | values: Contains the values to be selected from. |
| 61 | n_instances: Specifies how many indices and values to return. |
| 62 | Returns: |
| 63 | The indices and values of the n_instances largest values. |
| 64 | """ |
| 65 | assert n_instances <= values.shape[0], 'n_instances must be less or equal than the size of utility' |
| 66 | |
| 67 | max_idx = np.argpartition(-values, n_instances-1, axis=0)[:n_instances] |
| 68 | |
| 69 | return max_idx, values[max_idx] |
| 70 | |
| 71 | |
| 72 | def multi_argmin(values: np.ndarray, n_instances: int = 1) -> np.ndarray: |
no outgoing calls
no test coverage detected
searching dependent graphs…