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

Function mod

numpy/_core/strings.py:219–252  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

217@set_module("numpy.strings")
218@array_function_dispatch(_mod_dispatcher)
219def 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")

Callers 3

test_modMethod · 0.90
__mod__Method · 0.70
unwrapFunction · 0.50

Calls 1

_to_bytes_or_str_arrayFunction · 0.85

Tested by 1

test_modMethod · 0.72