Created
June 30, 2015 01:45
-
-
Save eayoungs/a61c7b09ec6f2e4af567 to your computer and use it in GitHub Desktop.
numpy multiply function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiply(a, i): | |
""" | |
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 : ndarray | |
Output array of str or unicode, depending on input types | |
""" | |
a_arr = numpy.asarray(a) | |
i_arr = numpy.asarray(i) | |
if not issubclass(i_arr.dtype.type, integer): | |
raise ValueError("Can only multiply by integers") | |
out_size = _get_num_chars(a_arr) * max(long(i_arr.max()), 0) | |
return _vec_string( | |
a_arr, (a_arr.dtype.type, out_size), '__mul__', (i_arr,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment