첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ poly1d 클래스를 사용해 2차 방정식을 생성하는 방법을 보여준다.

▶ 예제 코드 (PY)

import matplotlib.pyplot as pp
import numpy as np

xNDArray      = np.arange(0, 10, 0.01)
yNDArray      = 3 * xNDArray ** 2 + 3 * xNDArray + 5
yNoiseNDArray = yNDArray + np.random.randn(len(yNDArray))

sourcePolyfitNDArray = np.polyfit(xNDArray, yNoiseNDArray, 2) # 2차식
sourcePoly1d = np.poly1d(sourcePolyfitNDArray)

# pp.figure(figsize = (12, 8))

pp.plot(xNDArray, yNoiseNDArray, label = "noise", color = "y")
pp.plot(xNDArray, yNDArray, ls = "dashed", lw = 3, color = "b", label = "original")
pp.plot(xNDArray, sourcePoly1d(xNDArray), lw = 2, color = "r", label = "polyfit")

pp.show();
728x90
그리드형(광고전용)
Posted by icodebroker
,