Matsu
deep learning from scratch_ch.01 본문
deep learning/deep learning from scratch_1
deep learning from scratch_ch.01
Matsu 2021. 6. 10. 20:21
In [1]:
import numpy as np
In [2]:
A = np.array([[1, 2], [3, 4]])
B = np.array([10, 20])
A * B
Out[2]:
array([[10, 40],
[30, 80]])
브로드캐스팅 기능으로 형상이 다른 행렬끼리도 원소 곱이 가능
In [3]:
X = np.array([[51, 55],
[14, 19],
[0, 4]])
print(X)
[[51 55]
[14 19]
[ 0 4]]
In [4]:
X.shape
Out[4]:
(3, 2)
In [5]:
X[0]
Out[5]:
array([51, 55])
In [6]:
X[0][1]
Out[6]:
55
In [7]:
for row in X:
print(row)
[51 55]
[14 19]
[0 4]
In [8]:
X = X.flatten()
print(X)
[51 55 14 19 0 4]
flatten 은 1차원 배열로 전환(평탄화)
In [9]:
X[np.array([0, 2, 4])]
Out[9]:
array([51, 14, 0])
In [10]:
X > 15
Out[10]:
array([ True, True, False, True, False, False])
In [11]:
X[X > 15]
Out[11]:
array([51, 55, 19])
numpy 배열에 부등호 연산자를 사용한 결과는 boolean 배열. 이 boolean 배열을 사용해 배열 X에서 True에 해당하는 원소, 즉 값이 15보다 큰 원소만 꺼내는 게 가능
In [15]:
import matplotlib.pyplot as plt
%matplotlib inline
In [16]:
x = np.arange(0, 6, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()
x = np.arange(0, 6, 0.1) ==> 0, 0.1, 0.2, ..., 5.8, 5.9 라는 데이터를 생성
In [17]:
x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1, label = 'sin')
plt.plot(x, y2, linestyle = '--', label = 'cos')
plt.xlabel('x')
plt.ylabel('y')
plt.title('sin & cos')
plt.legend()
plt.show()
In [18]:
from matplotlib.image import imread
이미지를 표현해주는 메서드인 imshow() 를 사용하기 위해 imread() 호출
In [19]:
img = imread('andy_nothing_half_assed.jpg')
plt.imshow(img)
plt.show()
내가 좋아하는 쇼생크 탈출의 한 장면으로 실습!
'deep learning > deep learning from scratch_1' 카테고리의 다른 글
| deep learning from scratch_ch.03 (2) | 2021.06.17 |
|---|---|
| deep learning from scratch_ch.02 (1) | 2021.06.11 |
Comments