MCPcopy Create free account
hub / github.com/numpy/numpy / multiply

Function multiply

numpy/core/defchararray.py:344–387  ·  view source on GitHub ↗

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 ---------- a : array_like of str or unicode i : array_like of ints Returns ------- out : ndar

(a, i)

Source from the content-addressed store, hash-verified

342
343@array_function_dispatch(_multiply_dispatcher)
344def multiply(a, i):
345 """
346 Return (a * i), that is string multiple concatenation,
347 element-wise.
348
349 Values in `i` of less than 0 are treated as 0 (which yields an
350 empty string).
351
352 Parameters
353 ----------
354 a : array_like of str or unicode
355
356 i : array_like of ints
357
358 Returns
359 -------
360 out : ndarray
361 Output array of str or unicode, depending on input types
362
363 Examples
364 --------
365 >>> a = np.array(["a", "b", "c"])
366 >>> np.char.multiply(x, 3)
367 array(['aaa', 'bbb', 'ccc'], dtype='<U3')
368 >>> i = np.array([1, 2, 3])
369 >>> np.char.multiply(a, i)
370 array(['a', 'bb', 'ccc'], dtype='<U3')
371 >>> np.char.multiply(np.array(['a']), i)
372 array(['a', 'aa', 'aaa'], dtype='<U3')
373 >>> a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3))
374 >>> np.char.multiply(a, 3)
375 array([['aaa', 'bbb', 'ccc'],
376 ['ddd', 'eee', 'fff']], dtype='<U3')
377 >>> np.char.multiply(a, i)
378 array([['a', 'bb', 'ccc'],
379 ['d', 'ee', 'fff']], dtype='<U3')
380 """
381 a_arr = numpy.asarray(a)
382 i_arr = numpy.asarray(i)
383 if not issubclass(i_arr.dtype.type, integer):
384 raise ValueError("Can only multiply by integers")
385 out_size = _get_num_chars(a_arr) * max(int(i_arr.max()), 0)
386 return _vec_string(
387 a_arr, type(a_arr.dtype)(out_size), '__mul__', (i_arr,))
388
389
390def _mod_dispatcher(a, values):

Callers 11

__mul__Method · 0.90
__imul__Method · 0.90
pinvFunction · 0.90
test_basic_arithmeticMethod · 0.90
__mul__Method · 0.70
__rmul__Method · 0.70
outerFunction · 0.70
crossFunction · 0.70
__mul__Method · 0.50
__rmul__Method · 0.50
test_testArithmeticMethod · 0.50

Calls 4

_vec_stringFunction · 0.90
_get_num_charsFunction · 0.85
maxFunction · 0.70
maxMethod · 0.45

Tested by 2

test_basic_arithmeticMethod · 0.72
test_testArithmeticMethod · 0.40