For each element in `a`, return a copy with the leading and trailing characters removed. Calls `str.strip` element-wise. Parameters ---------- a : array-like of str or unicode chars : str or unicode, optional The `chars` argument is a string specifying the set
(a, chars=None)
| 1612 | |
| 1613 | @array_function_dispatch(_strip_dispatcher) |
| 1614 | def strip(a, chars=None): |
| 1615 | """ |
| 1616 | For each element in `a`, return a copy with the leading and |
| 1617 | trailing characters removed. |
| 1618 | |
| 1619 | Calls `str.strip` element-wise. |
| 1620 | |
| 1621 | Parameters |
| 1622 | ---------- |
| 1623 | a : array-like of str or unicode |
| 1624 | |
| 1625 | chars : str or unicode, optional |
| 1626 | The `chars` argument is a string specifying the set of |
| 1627 | characters to be removed. If omitted or None, the `chars` |
| 1628 | argument defaults to removing whitespace. The `chars` argument |
| 1629 | is not a prefix or suffix; rather, all combinations of its |
| 1630 | values are stripped. |
| 1631 | |
| 1632 | Returns |
| 1633 | ------- |
| 1634 | out : ndarray |
| 1635 | Output array of str or unicode, depending on input type |
| 1636 | |
| 1637 | See Also |
| 1638 | -------- |
| 1639 | str.strip |
| 1640 | |
| 1641 | Examples |
| 1642 | -------- |
| 1643 | >>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) |
| 1644 | >>> c |
| 1645 | array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7') |
| 1646 | >>> np.char.strip(c) |
| 1647 | array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7') |
| 1648 | >>> np.char.strip(c, 'a') # 'a' unstripped from c[1] because whitespace leads |
| 1649 | array(['AaAaA', ' aA ', 'bBABb'], dtype='<U7') |
| 1650 | >>> np.char.strip(c, 'A') # 'A' unstripped from c[1] because (unprinted) ws trails |
| 1651 | array(['aAaAa', ' aA ', 'abBABba'], dtype='<U7') |
| 1652 | |
| 1653 | """ |
| 1654 | a_arr = numpy.asarray(a) |
| 1655 | return _vec_string(a_arr, a_arr.dtype, 'strip', _clean_args(chars)) |
| 1656 | |
| 1657 | |
| 1658 | @array_function_dispatch(_unary_op_dispatcher) |
no test coverage detected