本文簡要介紹 python 語言中  numpy.searchsorted  的用法。
- 用法:- numpy.searchsorted(a, v, side='left', sorter=None)
- 查找應插入元素以保持順序的索引。 - 找到排序數組 a 中的索引,這樣,如果 v 中的相應元素插入到索引之前,則 a 的順序將被保留。 - 假設 a 已排序: - 邊 - 返回的索引 i 滿足 - left - a[i-1] < v <= a[i]- right - a[i-1] <= v < a[i]- a: 一維 數組
- 輸入數組。如果 sorter 為 None,則它必須按升序排序,否則 sorter 必須是對其進行排序的索引數組。 
- v: array_like
- 要插入到 a 中的值。 
- side: {‘left’, ‘right’},可選
- 如果‘left’,則給出找到的第一個合適位置的索引。如果‘right’,返回最後一個這樣的索引。如果沒有合適的索引,則返回 0 或 N(其中 N 是 a 的長度)。 
- sorter: 一維數組,可選
- 可選的整數索引數組,將數組 a 排序為升序。它們通常是 argsort 的結果。 
 
- indices: int 或整數數組
- 與 v 形狀相同的插入點數組,如果 v 是標量,則為整數。 
 
 - 參數:- 返回:- 注意:- 二分查找用於查找所需的插入點。 - 從 NumPy 1.4.0 開始, - searchsorted適用於包含- nan值的實數/複數數組。增強的排序順序記錄在- sort中。- 此函數使用與內置 python 相同的算法 - bisect.bisect_left(- side='left') 和- bisect.bisect_right(- side='right') 函數,這也是向量化的v爭論。- 例子:- >>> np.searchsorted([1,2,3,4,5], 3) 2 >>> 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])
相關用法
- Python numpy setdiff1d用法及代碼示例
- Python numpy seterr用法及代碼示例
- Python numpy seterrobj用法及代碼示例
- Python numpy set_printoptions用法及代碼示例
- Python numpy select用法及代碼示例
- Python numpy setxor1d用法及代碼示例
- Python numpy set_string_function用法及代碼示例
- Python numpy seterrcall用法及代碼示例
- Python numpy shape用法及代碼示例
- Python numpy scimath.log用法及代碼示例
- Python numpy signbit用法及代碼示例
- Python numpy sort用法及代碼示例
- Python numpy scimath.logn用法及代碼示例
- Python numpy square用法及代碼示例
- Python numpy std用法及代碼示例
- Python numpy scimath.log2用法及代碼示例
- Python numpy sum用法及代碼示例
- Python numpy spacing用法及代碼示例
- Python numpy squeeze用法及代碼示例
- Python numpy scimath.arccos用法及代碼示例
- Python numpy shares_memory用法及代碼示例
- Python numpy s_用法及代碼示例
- Python numpy swapaxes用法及代碼示例
- Python numpy sctype2char用法及代碼示例
- Python numpy show_config用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.searchsorted。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
