NumPy: multiply() function
numpy.core.defchararray.multiply() function
Return (a * i), that is string multiple concatenation, element-wise.
Values in i of less than 0 are treated as 0 (which yields an empty string).
Version: 1.15.0
numpy.core.defchararray.multiplySyntax:
numpy.core.defchararray.multiply(a, i)
Parameter:
Name | Description | Required / Optional |
---|---|---|
a: array_like of str or unicode | Input array. | Required |
i: array_like of ints | Input array | 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.multiply() function
import numpy as np
a1 = ['aaa', 'bbb', 'ccc']
a2 = ['ppp', 'qqq', 'rrr']
print("\na1 : ", a1)
print("\na2 : ", a2)
print("\na1 : ", np.char.multiply(a1, 2))
print ("\na1 : ", np.char.multiply(a1, [2, 4, 3]))
print ("\na2 : ", np.char.multiply(a2, 3))
Output:
a1 : ['aaa', 'bbb', 'ccc'] a2 : ['ppp', 'qqq', 'rrr'] a1 : ['aaaaaa' 'bbbbbb' 'cccccc'] a1 : ['aaaaaa' 'bbbbbbbbbbbb' 'ccccccccc'] a2 : ['ppppppppp' 'qqqqqqqqq' 'rrrrrrrrr']
Pictorial Presentation:
Pictorial Presentation:
Pictorial Presentation:
Example-2: numpy.multiply() function
import numpy as np
arr1 = 'Python'
arr2 = 'NumPy Tutorial '
print ("\narr1 : ", np.char.multiply(arr1, 2))
print ("\narr2 : ", np.char.multiply(arr2, 4))
Output:
arr1 : PythonPython arr2 : NumPy Tutorial NumPy Tutorial NumPy Tutorial NumPy Tutorial
Python - NumPy Code Editor:
- 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