
Data Science
264
def tensor
_
combine(f: Callable[[float, float], float],
t1: Tensor,
t2: Tensor) -> Tensor:
"""
두
텐서의
대칭되는
t1
과
t2
에
일괄적으로
함수를
적용
"""
if is
_
1d(t1):
return [f(x, y) for x, y in zip(t1, t2)]
else:
return [tensor
_
combine(f, t1
_
i, t2
_
i)
for t1
_
i, t2
_
i in zip(t1, t2)]
import operator
assert tensor
_
combine(operator.add, [1, 2, 3], [4, 5, 6]) == [5, 7, 9]
assert tensor
_
combine(operator.mul, [1, 2, 3], [4, 5, 6]) == [4, 10, 18]
19.2
층 추상화
18
장에서는 각각
sigmoid(dot(weights, inputs))
를 계산해 주는 두 층으로 구성
된 단순한 신경망을 만들어 보았다.
이러한 구조는 실제 뉴런이 작동하는 방식과 비슷하지만, 딥러닝에서는 다양
한 신경망 구조를 사용할 것이다. 가령 각 뉴런이 이전 입력값을 기억하도록 만
들거나 시그모이드 대신 다른 활성화 함수(
activation
function