numpy.char.multiply#

char.multiply(a, i)[source]#

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).

Parameters:
aarray_like, with np.bytes_ or np.str_ dtype
iarray_like, with any integer dtype
Returns:
outndarray

Output array of str or unicode, depending on input types

Notes

This is a thin wrapper around np.strings.multiply that raises ValueError when i is not an integer. It only exists for backwards-compatibility.

Examples

>>> a = np.array(["a", "b", "c"])
>>> np.strings.multiply(a, 3)
array(['aaa', 'bbb', 'ccc'], dtype='<U3')
>>> i = np.array([1, 2, 3])
>>> np.strings.multiply(a, i)
array(['a', 'bb', 'ccc'], dtype='<U3')
>>> np.strings.multiply(np.array(['a']), i)
array(['a', 'aa', 'aaa'], dtype='<U3')
>>> a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3))
>>> np.strings.multiply(a, 3)
array([['aaa', 'bbb', 'ccc'],
       ['ddd', 'eee', 'fff']], dtype='<U3')
>>> np.strings.multiply(a, i)
array([['a', 'bb', 'ccc'],
       ['d', 'ee', 'fff']], dtype='<U3')