
Numpy๋ ๋น
๋ฐ์ดํฐ ๋ถ์์ ์ํด ์ฌ์ฉํ๋ ๋ํ์ ์ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ค ํ๋์ด๋ค. Numpy์ ํต์ฌ์ ์ธ ์์๋ ndarray object(N์ฐจ์ ๋ฐฐ์ด ๊ฐ์ฒด)์ด๋ค.
ํ๋ ฌ, ๋ฒกํฐ ์ฐ์ฐ(์ ํ๋์)์ ์ํ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ๋น ๋ฅธ ์ฒ๋ฆฌ์๋๊ฐ ์ฅ์ ์ด๋ค.
np.array() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ์์ฐจ์ ์ธ ๊ฐ์ฒด๋ฅผ ๋ฐ์ np.array๋ก ๋ฐํํ๋ค.
shape๊ฐ ๊ฐ์ ndarray ์ฌ์น์ฐ์ฐ์ด ๊ฐ๋ฅํ๋ค.
EX) +, -, /, *
import numpy as np
# ํ๋ ฌ ๊ณฑ
np.matmul(a, b)
a @ b
# ๊ฐ์ฅ ํฐ ๊ฐ ๋ฐํ
a.max()
# ๊ฐ์ฅ ์์ ๊ฐ ๋ฐํ
a.min()
# ํ๊ท ๊ฐ ๋ฐํ
a.mean()
# ๋ฐฐ์ด์ ํํํ
a.flatten()
#์ด ๋ฐฉํฅ ์์
(axis = 0)
#ํ ๋ฐฉํฅ ์์
(axis = 1)
# 1์ฐจ์์ผ๋ก ๋ง๋ถ์ด๊ธฐ
np.append(a,b)
# ๋์ ์์ฑ
# (3,3) ๋์ ์์ฑ
np.random.rand(3,3)
# 0~10 ๊น์ง 10๊ฐ์ ๋์ ์์ฑ
np.random.randint(0, 10, size = 10)
# 0ํ๋ ฌ
np.zeros((2,3))
# ๋ชจ๋ ๊ฐ์ด 1์ธ ํ๋ ฌ
np.ones((2,3))
# ๋ชจ๋ ๊ฐ์ด 100์ธ ํ๋ ฌ
np.full((2,3), 100)
# ๋จ์ ํ๋ ฌ
np.eye(3)
# 0~10 ๊น์ง ๋ฐฐ์ด ์ฌ๊ตฌ์ฑ
np.arrange(0,10).reshape(2,5)
np.arrange(0,10).reshape(5,2)
# ์ ์นํ๋ ฌ
np.transpose(a)
a.transpose()
print(a[0])
# ์์ ์ธ๋ฑ์ฑ
print(a[-1])
# ์ฌ๋ฌ ๊ฐ์ ์์ ์ธ๋ฑ์ฑ
print(a[np.array([0,1])])
# ๋ฆฌ์คํธ ์ฌ๋ผ์ด์ฑ
a_list[1:5]