Problem 3
This commit is contained in:
parent
bcb127cce6
commit
a774076061
24
binomial_coeffs.py
Normal file
24
binomial_coeffs.py
Normal file
@ -0,0 +1,24 @@
|
||||
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
|
||||
|
||||
|
||||
N = 10
|
||||
print("N:", N)
|
||||
|
||||
coeffs = pascal(N)
|
||||
print("coefficients:", coeffs)
|
||||
|
||||
normalized_coeffs = coeffs / 2 ** N
|
||||
print("normalized coefficients:", normalized_coeffs)
|
||||
|
||||
expect_x = np.sum(normalized_coeffs) / len(normalized_coeffs)
|
||||
expect_x_sqrd = np.sum(normalized_coeffs ** 2) / len(normalized_coeffs)
|
||||
std = np.sqrt(expect_x_sqrd - expect_x ** 2)
|
||||
print("std", std)
|
Loading…
Reference in New Issue
Block a user