From c220469299158e7f68f43c33cd59ddfa2cd6d344 Mon Sep 17 00:00:00 2001 From: daniel <1534513+dantp-ai@users.noreply.github.com> Date: Tue, 5 Mar 2024 23:55:47 +0100 Subject: [PATCH] Implement zipWith and addWith --- minitorch/operators.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/minitorch/operators.py b/minitorch/operators.py index 5057471..1d2fc94 100644 --- a/minitorch/operators.py +++ b/minitorch/operators.py @@ -170,14 +170,16 @@ def zipWith( applying fn(x, y) on each pair of elements. """ - # TODO: Implement for Task 0.3. - raise NotImplementedError("Need to implement for Task 0.3") + + def new_fn(ls1: Iterable[float], ls2: Iterable[float]) -> Iterable[float]: + return [fn(ls1[i], ls2[i]) for i in range(len(ls1))] + + return new_fn def addLists(ls1: Iterable[float], ls2: Iterable[float]) -> Iterable[float]: "Add the elements of `ls1` and `ls2` using `zipWith` and `add`" - # TODO: Implement for Task 0.3. - raise NotImplementedError("Need to implement for Task 0.3") + return zipWith(add)(ls1, ls2) def reduce(