From 0cd119041ed1d3aa45bdd7ee3f9b9c91c9ef51d1 Mon Sep 17 00:00:00 2001 From: orosmatthew Date: Mon, 5 Feb 2024 12:03:36 -0500 Subject: [PATCH] Problem 1.1 --- 1.1.py | 26 ++++++++++++++++++++++++++ scratch.py | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 1.1.py diff --git a/1.1.py b/1.1.py new file mode 100644 index 0000000..943be53 --- /dev/null +++ b/1.1.py @@ -0,0 +1,26 @@ +import numpy as np + +ages = np.array([14, 15, 16, 16, 16, 22, 22, 24, 24, 25, 25, 25, 25, 25]) + +# a + +expect_j_sqrd = np.sum(ages ** 2) / ages.size +print(":", expect_j_sqrd) + +expect_j = np.sum(ages) / ages.size +print("^2:", expect_j ** 2) + +# b + +unique_ages = np.unique(ages) +unique_delta_js = unique_ages - expect_j +print("delta js:", [(unique_ages[i], unique_delta_js[i]) for i in range(len(unique_ages))]) + +delta_js = ages - expect_j +std_eq11 = np.sqrt(np.sum(delta_js ** 2) / delta_js.size) +print("std eq. 1.11:", std_eq11) + +# c + +std_eq12 = np.sqrt(expect_j_sqrd - expect_j ** 2) +print("std eq. 1.12:", std_eq12) diff --git a/scratch.py b/scratch.py index e69de29..55336bd 100644 --- a/scratch.py +++ b/scratch.py @@ -0,0 +1,20 @@ +import numpy as np +import math as m + + +def pascal(n: int) -> np.ndarray: + p = np.zeros(n + 1) + for i in range(n + 1): + p[i] = m.factorial(n) / (m.factorial(i) * m.factorial(n - i)) + return p + + +def normalized_pascal(n: int) -> np.ndarray: + return pascal(n) / 2 ** n + + +N = 10 +heads = np.arange(N + 1) +print("heads:", heads) + +print("pascal:", normalized_pascal(N))