numpy.strings.partition#

strings.partition(a, sep)[源代码]#

围绕 sep 分区 a 中的每个元素.

对于 a 中的每个元素,在 sep 的第一次出现处分割该元素,并返回一个包含分隔符之前的部分,分隔符本身以及分隔符之后的部分的 3 元组.如果未找到分隔符,则元组的第一个项目将包含整个字符串,第二个和第三个将为空字符串.

参数:
a: 类数组,具有 StringDType , bytes_str_ dtype类数组,具有

输入数组

sep : 类数组,具有 StringDType , bytes_str_ 数据类型类数组,具有

用于分割 a 中每个字符串元素的分隔符.

返回:
out3 元组:
  • 具有 StringDType , bytes_str_ dtype 的数组,包含分隔符之前的部分

  • 具有 StringDType , bytes_str_ dtype 的数组,包含分隔符

  • 具有 StringDType , bytes_str_ dtype 的数组,包含分隔符之后的部分

参见

str.partition

示例

>>> import numpy as np
>>> x = np.array(["Numpy is nice!"])
>>> np.strings.partition(x, " ")
(array(['Numpy'], dtype='<U5'),
 array([' '], dtype='<U1'),
 array(['is nice!'], dtype='<U8'))