Return (a % i), that is pre-Python 2.6 string formatting (interpolation), element-wise for a pair of array_likes of str or unicode. Parameters ---------- a : array_like, with ``bytes_`` or ``str_`` dtype values : array_like of values These values will be element
(a, values)
| 217 | @set_module("numpy.strings") |
| 218 | @array_function_dispatch(_mod_dispatcher) |
| 219 | def mod(a, values): |
| 220 | """ |
| 221 | Return (a % i), that is pre-Python 2.6 string formatting |
| 222 | (interpolation), element-wise for a pair of array_likes of str |
| 223 | or unicode. |
| 224 | |
| 225 | Parameters |
| 226 | ---------- |
| 227 | a : array_like, with ``bytes_`` or ``str_`` dtype |
| 228 | |
| 229 | values : array_like of values |
| 230 | These values will be element-wise interpolated into the string. |
| 231 | |
| 232 | Returns |
| 233 | ------- |
| 234 | out : ndarray |
| 235 | Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype, |
| 236 | depending on input types |
| 237 | |
| 238 | Examples |
| 239 | -------- |
| 240 | >>> import numpy as np |
| 241 | >>> a = np.array(["NumPy is a %s library"]) |
| 242 | >>> np.strings.mod(a, values=["Python"]) |
| 243 | array(['NumPy is a Python library'], dtype='<U25') |
| 244 | |
| 245 | >>> a = np.array([b'%d bytes', b'%d bits']) |
| 246 | >>> values = np.array([8, 64]) |
| 247 | >>> np.strings.mod(a, values) |
| 248 | array([b'8 bytes', b'64 bits'], dtype='|S7') |
| 249 | |
| 250 | """ |
| 251 | return _to_bytes_or_str_array( |
| 252 | _vec_string(a, np.object_, '__mod__', (values,)), a) |
| 253 | |
| 254 | |
| 255 | @set_module("numpy.strings") |