numpy.strings.partition#
- strings.partition(a, sep)[原始碼]#
在
sep
周圍分割a
中的每個元素。對於
a
中的每個元素,在第一次出現sep
的位置分割元素,並傳回一個 3 元組,其中包含分隔符號之前的部分、分隔符號本身以及分隔符號之後的部分。如果找不到分隔符號,則元組的第一個項目將包含整個字串,第二個和第三個項目將為空字串。- 參數:
- aarray-like,具有
StringDType
、bytes_
或str_
dtype 輸入陣列
- separray-like,具有
StringDType
、bytes_
或str_
dtype 用於分割
a
中每個字串元素的分隔符號。
- aarray-like,具有
- 傳回值:
- out3 元組:
陣列,具有
StringDType
、bytes_
或str_
dtype,包含分隔符號之前的部分陣列,具有
StringDType
、bytes_
或str_
dtype,包含分隔符號陣列,具有
StringDType
、bytes_
或str_
dtype,包含分隔符號之後的部分
另請參閱
範例
>>> 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'))