티스토리 뷰

import numpy as np

numpy라는 외부 클래스를 다음과 같이 import 해서 np로 사용한다.


x = np.array([1,2,3,4,5])

type(x)

다음과 같이 numpy.ndarray를 정의한다.


a = np.array([[1,2,],[3,4]])

np.linalg.det(a)

determinant도 계산 가능하다.


x[x>3]

true에 해당하는 원소들로만 이루어진 array가 출력된다.


import matplotlib.pyplot as plt

matplotlib의 pyplot을 import하여 plt로 사용한다.


x = np.arange(0, 6, 0.1)

y = np.sin(x)

np.arange를 이용하여 0부터 6까지 0.1씩 증가하는 숫자로 된 array를 생성한다.

numpy에는 sine function도 있다!


plt.plot(x,y)

plt.show()

plot으로 그리고 show로 화면에 띄운다.


y1 = np.sin(x)

y2 = np.cos(x)

plt.plot(x, y1, label="sine")

plt.plot(x, y2, linestyle="--", label="cosine")

plt.xlabel("x")

plt.ylabel("y")

plt.title('the two trigonometric functions')

plt.legend()

plt.show()

linestyle, label 옵션과 pyplot.xlabel(), pyplot.title(), pyplot.legend() 사용법 알아두기.

결과물은 하나의 그림으로 그려진다.


from matplotlib.image import imread

img = imread('C:\image_name.jpg')

plt.imshow(img)

plt.show()

그림이 뙇! 신기방기하다.




댓글
공지사항
글 보관함
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Total
Today
Yesterday