以下のコードでは、y1とy2は等しいはずですが、そうではありません。 vectorize()またはdot()にバグがありますか?グラフY1とY2のNumPy vectorize()またはdot()がバグに見える
import numpy as np
interval = np.arange(0, 30, 0.1)
y1 = [- 1.57 * max(0, x - 10) - 0.72 * max(0, 15 - x)
- 1.09 * max(0, 20 - x) for x in interval]
def fun(x, pivot, truth):
if truth: return max(0, x - pivot)
else: return max(0, pivot - x)
pivots = [10, 15, 20]
truths = [ 1, 0, 0]
coeffs = [-1.57, -0.72, -1.09]
y2 = [np.dot(np.vectorize(fun)(x, pivots, truths), coeffs) for x in interval]
import matplotlib.pyplot as plt
plt.plot(interval, y1, interval, y2)
plt.show()