What is the numpy.char.mod() function from NumPy in Python?
Overview
The char.mod() function in Python is simply used to return (a % i), which is pre-Python 2.6 string formatting, element-wise, for a pair of the array.
Syntax
char.mod(a, values)
Parameter value
The char.mod() function takes the following parameter values:
a: This represents an array object of strings or Unicode.values: This represents the values that will be interpolated element-wise into the string.
Return value
The char.mod() function returns an output array of strings or Unicode depending on the input type.
Code example
import numpy as np# creating an array objectmyarray = np.array([1, 10, 20])# implememting the char.mode() functionprint(np.char.mod('%d', myarray))
Code explanation
- Line 1: We import the
numpymodule. - Line 3: We create an array object
myarray. - Line 6: We implement the
char.mod()function on the values of the arraymyarrayand print our result.