def apply_multiple_masked(func, data, args=(), kwargs={}):
# Data is a sequence of arrays (i.e. X, y pairs for training)
datastack = []
dims = []
flat = []
for d in data:
if d.ndim == 2:
datastack.append(d)
dims.append(d.shape[1])
flat.append(False)
elif d.ndim == 1:
datastack.append(d[:, np.newaxis])
dims.append(1)
flat.append(True)
else:
raise RuntimeError("data arrays have to be 1 or 2D arrays")
# Decorate functions to work on stacked data
dims = np.cumsum(dims[:-1]) # dont split by last dim
unstack = lambda catdata: [d.flatten() if f else d for d, f
in zip(np.hsplit(catdata, dims), flat)]
unstackfunc = lambda catdata, *nargs, **nkwargs: \
func(*chain(unstack(catdata), nargs), **nkwargs)
return apply_masked(unstackfunc, np.ma.hstack(datastack), args, kwargs)
#
# Static module properties
#
# Add all models available to the learning pipeline here!
评论列表
文章目录