From 284afc630b3d0dd6c0079c6d3e83a73d6d1193e0 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sat, 16 May 2020 16:52:12 +0200 Subject: Added hpp assignments --- sem4/hpp/m9/opgave3.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 sem4/hpp/m9/opgave3.py (limited to 'sem4/hpp/m9/opgave3.py') diff --git a/sem4/hpp/m9/opgave3.py b/sem4/hpp/m9/opgave3.py new file mode 100644 index 0000000..15505eb --- /dev/null +++ b/sem4/hpp/m9/opgave3.py @@ -0,0 +1,31 @@ +import numpy as np + +def matrixmult(a, b): + res = np.empty((a.shape[0], b.shape[1])) + for ic, c in enumerate(b.T): + for ir, r in enumerate(a): + res[ir][ic] = np.dot(c, r) + + return res + +a = np.random.random((100, 300)) +b = np.random.random((300, 100)) + +print("a") +print(a) +print("b") +print(b) + +custom = matrixmult(a, b) + +ref = a @ b + +print("custom") +print(custom) +print("ref") +print(ref) + +if np.array_equal(custom, ref): + print("Yay they are the same, well done") +else: + print("Not the same, bummer") -- cgit v1.2.3