Partition (split) each element around the right-most separator. For each element in ``a``, split the element at the last occurrence of ``sep``, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separato
(a, sep)
| 1605 | @set_module("numpy.strings") |
| 1606 | @array_function_dispatch(_partition_dispatcher) |
| 1607 | def rpartition(a, sep): |
| 1608 | """ |
| 1609 | Partition (split) each element around the right-most separator. |
| 1610 | |
| 1611 | For each element in ``a``, split the element at the last |
| 1612 | occurrence of ``sep``, and return a 3-tuple containing the part |
| 1613 | before the separator, the separator itself, and the part after |
| 1614 | the separator. If the separator is not found, the third item of |
| 1615 | the tuple will contain the whole string, and the first and second |
| 1616 | ones will be the empty string. |
| 1617 | |
| 1618 | Parameters |
| 1619 | ---------- |
| 1620 | a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype |
| 1621 | Input array |
| 1622 | sep : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype |
| 1623 | Separator to split each string element in ``a``. |
| 1624 | |
| 1625 | Returns |
| 1626 | ------- |
| 1627 | out : 3-tuple: |
| 1628 | - array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the |
| 1629 | part before the separator |
| 1630 | - array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the |
| 1631 | separator |
| 1632 | - array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the |
| 1633 | part after the separator |
| 1634 | |
| 1635 | See Also |
| 1636 | -------- |
| 1637 | str.rpartition |
| 1638 | |
| 1639 | Examples |
| 1640 | -------- |
| 1641 | >>> import numpy as np |
| 1642 | >>> a = np.array(['aAaAaA', ' aA ', 'abBABba']) |
| 1643 | >>> np.strings.rpartition(a, 'A') |
| 1644 | (array(['aAaAa', ' a', 'abB'], dtype='<U5'), |
| 1645 | array(['A', 'A', 'A'], dtype='<U1'), |
| 1646 | array(['', ' ', 'Bba'], dtype='<U3')) |
| 1647 | |
| 1648 | """ |
| 1649 | a = np.asanyarray(a) |
| 1650 | sep = np.asanyarray(sep) |
| 1651 | |
| 1652 | if np.result_type(a, sep).char == "T": |
| 1653 | return _rpartition(a, sep) |
| 1654 | |
| 1655 | sep = sep.astype(a.dtype, copy=False) |
| 1656 | pos = _rfind_ufunc(a, sep, 0, MAX) |
| 1657 | a_len = str_len(a) |
| 1658 | sep_len = str_len(sep) |
| 1659 | |
| 1660 | not_found = pos < 0 |
| 1661 | buffersizes1 = np.where(not_found, 0, pos) |
| 1662 | buffersizes3 = np.where(not_found, a_len, a_len - pos - sep_len) |
| 1663 | |
| 1664 | out_dtype = ",".join([f"{a.dtype.char}{n}" for n in ( |