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

Function strip

numpy/_core/strings.py:1034–1077  ·  view source on GitHub ↗

For each element in `a`, return a copy with the leading and trailing characters removed. Parameters ---------- a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype chars : scalar with the same dtype as ``a``, optional The ``chars`` argument is a string

(a, chars=None)

Source from the content-addressed store, hash-verified

1032
1033@set_module("numpy.strings")
1034def strip(a, chars=None):
1035 """
1036 For each element in `a`, return a copy with the leading and
1037 trailing characters removed.
1038
1039 Parameters
1040 ----------
1041 a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
1042 chars : scalar with the same dtype as ``a``, optional
1043 The ``chars`` argument is a string specifying the set of
1044 characters to be removed. If ``None``, the ``chars``
1045 argument defaults to removing whitespace. The ``chars`` argument
1046 is not a prefix or suffix; rather, all combinations of its
1047 values are stripped.
1048
1049 Returns
1050 -------
1051 out : ndarray
1052 Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
1053 depending on input types
1054
1055 See Also
1056 --------
1057 str.strip
1058
1059 Examples
1060 --------
1061 >>> import numpy as np
1062 >>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
1063 >>> c
1064 array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
1065 >>> np.strings.strip(c)
1066 array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')
1067 # 'a' unstripped from c[1] because of leading whitespace.
1068 >>> np.strings.strip(c, 'a')
1069 array(['AaAaA', ' aA ', 'bBABb'], dtype='<U7')
1070 # 'A' unstripped from c[1] because of trailing whitespace.
1071 >>> np.strings.strip(c, 'A')
1072 array(['aAaAa', ' aA ', 'abBABba'], dtype='<U7')
1073
1074 """
1075 if chars is None:
1076 return _strip_whitespace(a)
1077 return _strip_chars(a, chars)
1078
1079
1080def _unary_op_dispatcher(a):

Callers 1

stripMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…