티스토리 뷰

함수 f(x) 정의

Numpy의 linspace 함수 사용: Return evenly spaced numbers over a specified interval

Pyplot의 plt 함수로 그래프 그리기  

(출처: 《파이썬으로 배우는 머신러닝의 교과서》, 코드는 멘토님이 제공)

 

원래 코드 

1
2
3
4
5
6
7
8
9
10
11
12
13
import numpy as np
import matplotlib.pyplot as plt
 
#함수 정의
def f(x): 
    return (x-2* x * (x+2)
 
#np.linspace: Return evenly spaced numbers over a specified interval.
= np.linspace(-3310#start, stop, Num(Number of samples to generate)
print(np.round(x, 2))
 
plt.plot(x, f(x))
plt.show
cs

결과물