[부스트코스] 코칭스터디 9기 : AI Basic 2023 3주차 미션(Q1, Q2, Q3, Q4) 변형 문제 풀이

2023. 2. 7. 16:59BOOTCAMP/boostcourse AI BASIC 2023

Q1. 무작위의 데이터를 가진 4x3의 행렬을 가지는 numpy array와 3x2 행렬을 가지는 numpy array를 만든 후 행열곱 연산을 진행해 보세요.

 

Input

import numpy as np

arr1 = np.random.rand(4, 3)
arr2 = np.random.rand(3, 2)

dot = np.dot(arr1, arr2)
print(dot, dot.shape)

Output

[[0.74783254 0.83914466]
 [1.00723028 1.53956107]
 [1.31310099 1.56683021]
 [1.34259143 1.5164803 ]] (4, 2)

Q2. 두 numpy array의 concatenate 연산을 구해보세요.

arr1 = np.array([[2, 4], [4, 13]], float)
arr2 = np.array([[5, 8], [9, 16]], float)

Input

concat_1 = np.concatenate((arr1,arr2), axis=0)
concat_1

Output

array([[ 2.,  4.],
       [ 4., 13.],
       [ 5.,  8.],
       [ 9., 16.]])

Input

concat_2 = np.concatenate((arr1,arr2), axis=1)
concat_2

Output

array([[ 2.,  4.,  5.,  8.],
       [ 4., 13.,  9., 16.]])

Q3. 아래와 같이 데이터가 주어져있을 때, 경사하강법을 위한 데이터를 분리해 보세요.

*주어진 xy 데이터를 이용해서 학습과 정답 데이터를 준비해 보세요.

import numpy as np

xy = np.array([[7., 9., 11., 15., 18., 22.],
              [30., 40., 50., 60., 70., 80.]])

Input

import numpy as np

xy = np.array([[7., 9., 11., 15., 18., 22.],
              [30., 40., 50., 60., 70., 80.]])

x_train = xy[0]
y_train = xy[1]

print(x_train, x_train.shape)
print(y_train, y_train.shape)

Output

[ 7.  9. 11. 15. 18. 22.] (6,)
[30. 40. 50. 60. 70. 80.] (6,)

Q4. 경사 하강법 구현을 위해서 위에서 분리한 x_train 데이터와 계산될 weight, bias 값을 정의해 보세요.

 

Input

beta_gd = np.random.rand(1)
bias = np.random.rand(1)

print(beta_gd, bias)

Output

[0.02547554] [0.01124154]