Numpy 的 startswith(~)
方法檢查輸入數組中的每個字符串是否以指定的子字符串開頭。
參數
1. a
| array-like
輸入字符串。
2. prefix
| array-like
您要檢查的起始子字符串。
3. start
| int
| optional
開始檢查的起始索引(包含)。
4. end
| int
| optional
要結束檢查的索引(含)。
返回值
如果 a
是標量,則返回單個布爾值。否則,返回一個 Numpy 布爾數組。
例子
指定前綴
np.char.startswith(["abcde"], ["ab"])
array([ True])
指定開始
np.char.startswith(["abcde"], ["ab"], start=1)
array([False])
在這裏,我們從索引 1 開始,這意味著我們正在檢查字符串 "bcde"
,該字符串不以 "ab"
開頭。
指定結束
np.char.startswith(["abcde"], ["abc"], end=2)
array([False])
在這裏,我們以索引 2 結束,這意味著我們正在檢查字符串 "ab"
,該字符串不以 "abc"
開頭。
相關用法
- Python numpy string startswith()用法及代碼示例
- Python startswith() and endswith()用法及代碼示例
- Python Scipy stats.cumfreq()用法及代碼示例
- Python Scipy stats.nanmean()用法及代碼示例
- Python Scipy stats.gengamma()用法及代碼示例
- Python Scipy stats.dweibull()用法及代碼示例
- Python scipy stats.expon()用法及代碼示例
- Python statistics.median_grouped用法及代碼示例
- Python Scipy stats.f()用法及代碼示例
- Python Scipy stats.genexpon()用法及代碼示例
- Python Scipy stats.genextreme()用法及代碼示例
- Python Sympy stats.P()用法及代碼示例
- Python Scipy stats.alpha()用法及代碼示例
- Python Scipy stats.halfgennorm()用法及代碼示例
- Python Scipy stats.skewtest()用法及代碼示例
- Python Scipy stats.exponweib()用法及代碼示例
- Python scipy stats.frechet_r用法及代碼示例
- Python Scipy stats.cauchy()用法及代碼示例
- Python Scipy stats.tstd()用法及代碼示例
- Python Scipy stats.halfnorm()用法及代碼示例
- Python Scipy stats.moment()用法及代碼示例
- Python statistics mean()用法及代碼示例
- Python Scipy stats.bayes_mvs()用法及代碼示例
- Python Scipy stats.gmean()用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | startswith method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。