Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def get_extremum_indices(
- ordinates: np.ndarray,
- ) -> tuple[np.ndarray, np.ndarray]:
- dif_sign = np.sign(np.array(ordinates[1:] - ordinates[:-1]))
- dif_dif = dif_sign[1:] - dif_sign[:-1]
- mask_max = dif_dif == -2
- mask_min = dif_dif == 2
- indices = np.arange(2, ordinates.shape[0]) - 1 #так как -2 и 2 указывают на предыдущий элемент
- max_indices = indices[mask_max]
- min_indices = indices[mask_min]
- return min_indices, max_indices
- a = np.array([7, 8, 6, 2, 4, 7, 0, 2, 8, 7, 7, 0, 9, 9, 7])
- res = get_extremum_indices(a)
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement