Hướng dẫn dùng numpy searchsorted python - using numpy searchsorted python

numpy.SearchSorted [a, v, side = 'left', sorter = none] [nguồn]#searchsorted[a, v, side='left', sorter=None][source]#

Tìm các chỉ số nơi các yếu tố nên được chèn để duy trì trật tự.

Tìm các chỉ số thành một mảng được sắp xếp sao cho các phần tử tương ứng trong V được chèn trước các chỉ số, thứ tự của A sẽ được bảo tồn.

Giả sử rằng A được sắp xếp:

cạnh

đã trả về chỉ số tôi thỏa mãn

bên trái

a[i-1] >> np.searchsorted[[1,2,3,4,5], 3, side='right'] 3 >>> np.searchsorted[[1,2,3,4,5], [-10, 10, 2, 3]] array[[0, 5, 1, 2]]

& nbsp; mã số 2:function is used to find the indices into a sorted array arr such that, if elements are inserted before the indices, the order of arr would be still preserved. Here, binary search is used to find the required insertion indices.

a[i-1]

Bài Viết Liên Quan

Chủ Đề