0909
3주차-Day2) Numpy 실습
2차원 배열 슬라이싱 연습 1
import numpy as np
def solution(arr, y1, x1, y2, x2):
arr[y1:y2+1, x1:x2+1] = arr[y1:y2+1, x1:x2+1] * 2
return arr
행렬 곱 실습문제
import numpy as np
def solution(arr_list):
A = np.array([[0]])
for arr in arr_list:
if len(A[0]) == len(arr):
A = np.dot(A + 1, arr * 2)
return A
y = w^T + b
import numpy as np
def solution(x, w, b):
answer = 0
for i in range(len(x)):
answer += x[i]*w[i]
answer += b
return answer
롤러코스터
import numpy as np
def solution(info):
answer = []
for i in range(len(info[0])):
a = 1 if 195 >= info[0][i] >= 150 else 0
b = 1 if 140 > info[1][i] else 0
if a*b == 0:
answer.append(i)
return answer
이미지 변환
import numpy as np
def solution(img):
R = img[:,:,0]
G = img[:,:,1]
B = img[:,:,2]
answer = R * 0.3 + G * 0.5 + B * 0.2
return answer