numpy.char.startswith#
- char.startswith(a, prefix, start=0, end=None)[源代码]#
返回一个布尔数组,如果
a中的字符串元素以prefix开头,则为 True,否则为 False。- 参数:
- a类数组,具有
StringDType、bytes_或str_数据类型 - prefix类数组对象,具有
StringDType,bytes_, 或str_数据类型 - start, end类数组,具有任何整数数据类型
使用
start,则从该位置开始测试。使用end,则在此位置停止比较。
- a类数组,具有
- 返回:
- outndarray
布尔值输出数组
另请参阅
示例
>>> import numpy as np >>> s = np.array(['foo', 'bar']) >>> s array(['foo', 'bar'], dtype='<U3') >>> np.strings.startswith(s, 'fo') array([True, False]) >>> np.strings.startswith(s, 'o', start=1, end=2) array([True, False])