
214
付録 演習の解答
v_edge = values @ vsobel_r
return np.hypot(h_edge, v_edge)
これを硬貨の画像に適用してみましょう。
sobel_mag = ndi.generic_filter(coins, sobel_magnitude_filter, size=3)
plt.imshow(sobel_mag, cmap='viridis');
■
A.4
解答:
SciPy
を使った曲線回帰
以下は「
3.5.1
演習:
SciPy
を使った曲線回帰」の解答です。
curve_fit
関数のドキュメントの先頭部分を見てみましょう。
Use nonlinear least squares to fit a function, f, to data.
非線形最小二乗法を使って関数
f
をデータに回帰する。
Assumes ``ydata = f(xdata, *params) + eps``
``ydata = f(xdata, *params) + eps``
を仮定。
Parameters
パラメータ
----------
f : callable
呼び出し可能
The model function, f(x, ...). It must take the independent
variable as the first argument and the parameters to fit as
図
A-2
水平と垂直のソーベルフィルタをかけた硬貨の画像