MCPcopy Index your code
hub / github.com/numpy/numpy / partition

Function partition

numpy/_core/defchararray.py:319–357  ·  view source on GitHub ↗

Partition each element in `a` around `sep`. Calls :meth:`str.partition` element-wise. For each element in `a`, split the element as the first occurrence of `sep`, and return 3 strings containing the part before the separator, the separator itself, and the part after the se

(a, sep)

Source from the content-addressed store, hash-verified

317
318@set_module("numpy.char")
319def partition(a, sep):
320 """
321 Partition each element in `a` around `sep`.
322
323 Calls :meth:`str.partition` element-wise.
324
325 For each element in `a`, split the element as the first
326 occurrence of `sep`, and return 3 strings containing the part
327 before the separator, the separator itself, and the part after
328 the separator. If the separator is not found, return 3 strings
329 containing the string itself, followed by two empty strings.
330
331 Parameters
332 ----------
333 a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
334 Input array
335 sep : {str, unicode}
336 Separator to split each string element in `a`.
337
338 Returns
339 -------
340 out : ndarray
341 Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
342 depending on input types. The output array will have an extra
343 dimension with 3 elements per input element.
344
345 Examples
346 --------
347 >>> import numpy as np
348 >>> x = np.array(["Numpy is nice!"])
349 >>> np.char.partition(x, " ")
350 array([['Numpy', ' ', 'is nice!']], dtype='<U8')
351
352 See Also
353 --------
354 str.partition
355
356 """
357 return np.stack(strings_partition(a, sep), axis=-1)
358
359
360@set_module("numpy.char")

Callers 1

partitionMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…