, , vectorize .
return dtype, - . , 0, vectorize . , , , return dtype.
- vectorize . . , .
np.vectorize(fun, otypes=[float])
.
===========
:
vfun = np.vectorize(fun, otypes=[float])
X = vfun(interval[:,None], pivots, truths)
print(X.shape)
y2 = np.dot(X, coeffs)
print(y2.shape)
vectorize's.
, fun , x, , vectorize.
fun np.maximum, x:
def fun(x, pivot, truth):
if truth: return np.maximum(0, x - pivot)
else: return np.maximum(0, pivot - x)
x 3 pivots truths, interval:
X = np.stack([fun(interval, p, t) for p, t in zip(pivots, truths)], axis=-1)
y2 = np.dot(X, coeffs)
3 ''
Xlist = [fun(interval, p, t)*c for p, t, c in zip(pivots, truths, coeffs)]
y2 = np.sum(Xlist, axis=0)
np.dot(..., coeffs) . , .