From 126fb14a07dbb1ea0d77df1e6930df4622d2de9a Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Sun, 23 Feb 2020 22:13:12 +0100
Subject: [PATCH] NumPy: Fibonacci-like

---
 02-numpy/fib-solve.py | 15 +++++++++++++++
 02-numpy/fib-test.py  |  6 ++++++
 2 files changed, 21 insertions(+)
 create mode 100755 02-numpy/fib-solve.py
 create mode 100755 02-numpy/fib-test.py

diff --git a/02-numpy/fib-solve.py b/02-numpy/fib-solve.py
new file mode 100755
index 0000000..5a4caa9
--- /dev/null
+++ b/02-numpy/fib-solve.py
@@ -0,0 +1,15 @@
+#!/usr/bin/python3
+
+import numpy as np
+
+n = 10
+
+a = -np.eye(n)/2 - np.eye(n, k=1)/2 + np.eye(n, k=2)
+a[-2:, -2:] = np.eye(2)
+
+b = np.zeros(n)
+b[-2] = 426
+b[-1] = 427
+
+x = np.linalg.solve(a, b)
+print(x[:2])
diff --git a/02-numpy/fib-test.py b/02-numpy/fib-test.py
new file mode 100755
index 0000000..7f3de42
--- /dev/null
+++ b/02-numpy/fib-test.py
@@ -0,0 +1,6 @@
+#!/usr/bin/python3
+
+a = [256, 512]
+for i in range(2, 10):
+    a.append((a[-1] + a[-2]) / 2)
+print(a)
-- 
GitLab