| [ Web Proxy ] |
| Viewing: https://numpy.org/doc/stable/reference/generated/../c-api/../generated/numpy.strings.slice.html | [Back] [Original] |
Slice the strings in a by slices specified by start, stop, step.
Like in the regular Python slice object, if only start is
specified then it is interpreted as the stop.
StringDType, bytes_, or str_ dtypeInput array
The start of the slice, broadcasted to as shape
The end of the slice, broadcasted to as shape
The step for the slice, broadcasted to as shape
Output array of StringDType, bytes_ or str_ dtype,
depending on input type
Examples
>>> import numpy as np
>>> a = np.array(['hello', 'world'])
>>> np.strings.slice(a, 2)
array(['he', 'wo'], dtype='<U5')
>>> np.strings.slice(a, 2, None)
array(['llo', 'rld'], dtype='<U5')
>>> np.strings.slice(a, 1, 5, 2)
array(['el', 'ol'], dtype='<U5')
One can specify different start/stop/step for different array entries:
>>> np.strings.slice(a, np.array([1, 2]), np.array([4, 5]))
array(['ell', 'rld'], dtype='<U5')
Negative slices have the same meaning as in regular Python:
>>> b = np.array(['hello world', ' ', '', ' '],
... dtype=np.dtypes.StringDType())
>>> np.strings.slice(b, -2)
array(['hello wor', ' ', '', ''], dtype=StringDType())
>>> np.strings.slice(b, -2, None)
array(['ld', '', '', ' '], dtype=StringDType())
>>> np.strings.slice(b, [3, -10, 2, -3], [-1, -2, -1, 3])
array(['lo worl', ' ', '', ' '], dtype=StringDType())
>>> np.strings.slice(b, None, None, -1)
array(['dlrow olleh', ' ', '', ' '],
dtype=StringDType())
| Web Proxy Viewer | New URL | Original Page |