Last active
July 21, 2017 20:29
-
-
Save bmweiner/4d022eacf429de15ff477bc864d9cae1 to your computer and use it in GitHub Desktop.
Common routines with numpy
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
from functools import reduce | |
import numpy as np | |
def mor(x): | |
"""x: iterable of np.array.""" | |
return reduce(np.logical_or, x) | |
def mand(x): | |
"""x: iterable of np.array.""" | |
return reduce(np.logical_and, x) | |
def madd(x): | |
"""Performs element-wise string concatenation with multiple input arrays. | |
Args: | |
x: iterable of np.array. | |
Returns: np.array. | |
""" | |
for i, arr in enumerate(x): | |
if type(arr.item(0)) is not str: | |
x[i] = x[i].astype(str) | |
return reduce(np.core.defchararray.add, x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment