adding pandas solution as a reference to the 'means of subsets' exercise
This commit is contained in:
@@ -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())"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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? (★★★)
|
||||||
|
|||||||
Reference in New Issue
Block a user