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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。