adding pandas solution as a reference to the 'means of subsets' exercise

This commit is contained in:
ibah
2016-10-04 11:57:43 +02:00
parent 497f204914
commit 9e3eb1d1dd
2 changed files with 9 additions and 1 deletions

View File

@@ -1467,7 +1467,11 @@
"D_sums = np.bincount(S, weights=D)\n", "D_sums = np.bincount(S, weights=D)\n",
"D_counts = np.bincount(S)\n", "D_counts = np.bincount(S)\n",
"D_means = D_sums / D_counts\n", "D_means = D_sums / D_counts\n",
"print(D_means)" "print(D_means)\n",
"\n",
"# Pandas solution as a reference due to more intuitive code\n",
"import pandas as pd\n",
"print(pd.Series(D).groupby(S).mean())"
] ]
}, },
{ {

View File

@@ -714,6 +714,10 @@ D_sums = np.bincount(S, weights=D)
D_counts = np.bincount(S) D_counts = np.bincount(S)
D_means = D_sums / D_counts D_means = D_sums / D_counts
print(D_means) print(D_means)
# Pandas solution as a reference due to more intuitive code
import pandas as pd
print(pd.Series(D).groupby(S).mean())
``` ```
#### 69. How to get the diagonal of a dot product? (★★★) #### 69. How to get the diagonal of a dot product? (★★★)