Created
March 3, 2016 15:26
-
-
Save smidm/6cb14ac3d82fd24c657d to your computer and use it in GitHub Desktop.
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
# modified numpy concatenate, vstack, hstack accepting scalars in the input tuple | |
def concatenate(tup, axis=0): | |
tup_arrays = [x for x in tup if isinstance(x, np.ndarray)] | |
shape = list(tup_arrays[0].shape) | |
shape[axis] = 1 | |
tup_ = [] | |
for x in tup: | |
if isinstance(x, (int, long, float)): | |
tup_.append(np.ones(shape) * x) | |
else: | |
tup_.append(x) | |
return np.concatenate(tup_, axis=axis) | |
def vstack(tup): | |
return concatenate(tup, 0) | |
def hstack(tup): | |
return concatenate(tup, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment