Skip to content

Commit 502ea87

Browse files
suda-yugaoyamadHumphreyYang
authored
[stats_examples] Replace np.sum(a * b) with a @ b (#476)
* Replace np.sum(a * b) with a @ b * Update lectures/prob_matrix.md Co-authored-by: Daisuke Oyama <Oyama.Daisuke@gmail.com> * migrate the changes to the splitted lecture --------- Co-authored-by: Daisuke Oyama <Oyama.Daisuke@gmail.com> Co-authored-by: Humphrey Yang <u6474961@anu.edu.au>
1 parent 1ca080e commit 502ea87

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lectures/stats_examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ We verify the above and compute the mean and variance using `numpy`.
172172

173173
```{code-cell} ipython3
174174
Benford_pmf = np.array([np.log10(1+1/d) for d in range(1,10)])
175-
k = np.array(range(1,10))
175+
k = np.arange(1, 10)
176176
177177
# mean
178-
mean = np.sum(Benford_pmf * k)
178+
mean = k @ Benford_pmf
179179
180180
# variance
181-
var = np.sum([(k-mean)**2 * Benford_pmf])
181+
var = ((k - mean) ** 2) @ Benford_pmf
182182
183183
# verify sum to 1
184184
print(np.sum(Benford_pmf))

0 commit comments

Comments
 (0)