def relu_forward(x):
out = np.zeros((x.shape[0], x.shape[1]), dtype=np.float64)
for i in range(x.shape[0]):
for j in range(x.shape[1]):
item_val = x[i, j]
print("element:" ,item_val)
out[i, j] = np.max(0.0, item_val)
cache = x
return out, cache
Reason
- array indexing을 할 때 정수가 아닌 float로 한 경우.
- 이거인 줄 알았는데, 여기서는 np.max 함수 자체를 잘못 쓴 거였음.
- np.max는 단일 array 내의 최대값. np.max(array) 형태임. axis는 기본이 None.
- np.maximum : 여러 array 사이의 각 위치의 최대값.
- ex
a = np.array([[2, 10], [3, 7]])
b = np.array([[6, -2], [1, 14]])
np.maximum(a, b)
결과
Solve
- index가 float라서 발생한 게 아니라 numpy.max 함수 사용법을 잘못 알아서였음^_^
- np.maximum 써서 비교 array 둬서 해결!