NumPy: mod() function
numpy.core.defchararray.mod() function
The numpy.core.defchararray.mod() function returns (a % i), that is pre-Python 2.6 string formatting (iterpolation), element-wise for a pair of array_likes of str or unicode.
Version: 1.15.0
Syntax:
numpy.core.defchararray.mod(a, values)
Parameter:
Name | Description | Required / Optional |
---|---|---|
a: array_like of str or unicode | Input array. | Required |
values: array_like of ints | These values will be element-wise interpolated into the string. | Required |
Return value:
out : ndarray - Output array of str or unicode, depending on input types.
Note:
The 'chararray' class exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of 'dtype' 'object_', 'string_' or 'unicode_', and use the free functions in the 'numpy.char' module for fast vectorized string operations.
Some methods will only be available if the corresponding string method is available in your version of Python.
The preferred alias for 'defchararray' is 'numpy.char'.
Example-1: numpy.mod() function
import numpy as np
a = np.array([0, 120, 1254872])
print("Integer arays:")
print (a)
print("String arrays")
s = np.char.mod('%d', a)
print(s)
Output:
Integer arays: [ 0 120 1254872] String arrays: ['0' '120' '1254872']
Previous:
multiply()
Next:
capitalize()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework