numpy.strings.lstrip#
- strings.lstrip(a, chars=None)[source]#
对于 a 中的每个元素,返回一个移除了前导字符的副本。
- 参数:
- a类数组,具有
StringDType
、bytes_
或str_
数据类型 - chars标量,与
a
具有相同的数据类型,可选 chars
参数是一个字符串,指定要移除的字符集。如果为None
,则chars
参数默认移除空白字符。chars
参数不是前缀或后缀;相反,它的所有值的组合都将被移除。
- a类数组,具有
- 返回:
- outndarray
输出数组,类型为
StringDType
、bytes_
或str_
,具体取决于输入类型
另请参阅
示例
>>> import numpy as np >>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7') # The 'a' variable is unstripped from c[1] because of leading whitespace. >>> np.strings.lstrip(c, 'a') array(['AaAaA', ' aA ', 'bBABba'], dtype='<U7') >>> np.strings.lstrip(c, 'A') # leaves c unchanged array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7') >>> (np.strings.lstrip(c, ' ') == np.strings.lstrip(c, '')).all() np.False_ >>> (np.strings.lstrip(c, ' ') == np.strings.lstrip(c)).all() np.True_