For each element in `a`, return a copy of the string where all characters occurring in the optional argument `deletechars` are removed, and the remaining characters have been mapped through the given translation table. Calls :meth:`str.translate` element-wise. Parameters
(a, table, deletechars=None)
| 1679 | @set_module("numpy.strings") |
| 1680 | @array_function_dispatch(_translate_dispatcher) |
| 1681 | def translate(a, table, deletechars=None): |
| 1682 | """ |
| 1683 | For each element in `a`, return a copy of the string where all |
| 1684 | characters occurring in the optional argument `deletechars` are |
| 1685 | removed, and the remaining characters have been mapped through the |
| 1686 | given translation table. |
| 1687 | |
| 1688 | Calls :meth:`str.translate` element-wise. |
| 1689 | |
| 1690 | Parameters |
| 1691 | ---------- |
| 1692 | a : array-like, with ``bytes_`` or ``str_`` dtype |
| 1693 | |
| 1694 | table : str of length 256 |
| 1695 | |
| 1696 | deletechars : str |
| 1697 | |
| 1698 | Returns |
| 1699 | ------- |
| 1700 | out : ndarray |
| 1701 | Output array of str or unicode, depending on input type |
| 1702 | |
| 1703 | See Also |
| 1704 | -------- |
| 1705 | str.translate |
| 1706 | |
| 1707 | Examples |
| 1708 | -------- |
| 1709 | >>> import numpy as np |
| 1710 | >>> a = np.array(['a1b c', '1bca', 'bca1']) |
| 1711 | >>> table = a[0].maketrans('abc', '123') |
| 1712 | >>> deletechars = ' ' |
| 1713 | >>> np.char.translate(a, table, deletechars) |
| 1714 | array(['112 3', '1231', '2311'], dtype='<U5') |
| 1715 | |
| 1716 | """ |
| 1717 | a_arr = np.asarray(a) |
| 1718 | if issubclass(a_arr.dtype.type, np.str_): |
| 1719 | return _vec_string( |
| 1720 | a_arr, a_arr.dtype, 'translate', (table,)) |
| 1721 | else: |
| 1722 | return _vec_string( |
| 1723 | a_arr, |
| 1724 | a_arr.dtype, |
| 1725 | 'translate', |
| 1726 | [table] + _clean_args(deletechars) |
| 1727 | ) |
| 1728 | |
| 1729 | @set_module("numpy.strings") |
| 1730 | def slice(a, start=None, stop=np._NoValue, step=None, /): |
no test coverage detected
searching dependent graphs…