Problem 1.2
This commit is contained in:
parent
0cd119041e
commit
bcb127cce6
6
1.1.py
6
1.1.py
@ -4,10 +4,10 @@ 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
|
||||
expect_j_sqrd = np.sum(ages ** 2) / len(ages)
|
||||
print("<j^2>:", expect_j_sqrd)
|
||||
|
||||
expect_j = np.sum(ages) / ages.size
|
||||
expect_j = np.sum(ages) / len(ages)
|
||||
print("<j>^2:", expect_j ** 2)
|
||||
|
||||
# b
|
||||
@ -17,7 +17,7 @@ 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)
|
||||
std_eq11 = np.sqrt(np.sum(delta_js ** 2) / len(delta_js))
|
||||
print("std eq. 1.11:", std_eq11)
|
||||
|
||||
# c
|
||||
|
27
1.2.py
Normal file
27
1.2.py
Normal file
@ -0,0 +1,27 @@
|
||||
import numpy as np
|
||||
|
||||
pi_digits = np.array([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3])
|
||||
|
||||
# a
|
||||
|
||||
unique_digits, counts = np.unique(pi_digits, return_counts=True)
|
||||
digit_probs = counts / len(pi_digits)
|
||||
print("digit probabilities:", [(unique_digits[i], digit_probs[i]) for i in range(len(unique_digits))])
|
||||
|
||||
# b
|
||||
|
||||
most_probable_digit = np.argmax(digit_probs)
|
||||
print("most probable digit:", most_probable_digit)
|
||||
|
||||
median_digit = np.sort(pi_digits)[len(pi_digits) // 2]
|
||||
print("median digit:", median_digit)
|
||||
|
||||
digit_average = np.sum(pi_digits) / len(pi_digits)
|
||||
print("digit average:", digit_average)
|
||||
|
||||
# c
|
||||
|
||||
expect_j_sqrd = np.sum(pi_digits ** 2) / len(pi_digits)
|
||||
expect_j = np.sum(pi_digits) / len(pi_digits)
|
||||
std = np.sqrt(expect_j_sqrd - expect_j ** 2)
|
||||
print("std:", std)
|
Loading…
Reference in New Issue
Block a user