๋ชฉ์ฐจ
์ ๊ธฐ
numpy๋,
์์น ํด์์ฉ ํ์ด์ฌ ํจํค์ง! 1์ฐจ์~3์ฐจ์ ๋ฐฐ์ด์ ์ฌ์ฉํ ์ ์๋ค.
1์ฐจ์ ๋ฐฐ์ด
import numpy as np
# numpy์ 1์ฐจ์ ๋ฐฐ์ด-------------------------------
# arrryํจ์์ ๋ฆฌ์คํธ๋ฅผ ๋ฃ์ผ๋ฉด ๋ฐฐ์ด๋ก ๋ณํ
ar = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) # ndarray ์๋ฃํ์ด๊ณ , ()์์ ์ํ์ค ๋ฐ์ดํฐ๋ฅผ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
print(ar)
print('ar ์๋ฃํ :', type(ar))
# ๋ฐฑํฐํ ์ฐ์ฐ--------------------------------------
data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# 1.for๋ฌธ์ ์ด์ฉํ ์ฐ์ฐ๋ฐฉ์
answer = []
for di in data:
answer.append((2*di))
print('data์ 2๋ฐฐ์ :', answer)
# 2. ๋ฐฑํฐํ ์ฐ์ฐ
x = np.array(data)
print('๋ฐฑํฐํ ์ฐ์ฐ :', x*2)
# 3. ๋ฐฑํฐํ ์ฐ์ฐ
a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print('๋ฐฑํฐํ ์ฐ์ฐ2 :', 2*a+b)
print('a๋ 2 ์ธ๊ฐ? :', a == 2)
print('b๋ 10๋ณด๋ค ํฐ๊ฐ? :', b > 10)
print('a๋ 2์ด๊ณ b๋ 10๋ณด๋ค ํฐ๊ฐ? :', (a == 2) & (b > 10))
[์คํ ๊ฒฐ๊ณผ]
[0 1 2 3 4 5 6 7 8 9]
ar ์๋ฃํ : <class 'numpy.ndarray'>
data์ 2๋ฐฐ์ : [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
๋ฐฑํฐํ ์ฐ์ฐ : [ 0 2 4 6 8 10 12 14 16 18]
๋ฐฑํฐํ ์ฐ์ฐ2 : [12 24 36]
a๋ 2 ์ธ๊ฐ? : [False True False]
b๋ 10๋ณด๋ค ํฐ๊ฐ? : [False True True]
a๋ 2์ด๊ณ b๋ 10๋ณด๋ค ํฐ๊ฐ? : [False True False]
728x90