Added example
+17 · 1 file changed
-
README.rst+17 −0
@@ -364,6 +364,22 @@ Journeyman sum = A.reshape(A.shape[:-2] + (-1,)).sum(axis=-1) +7. Considering a one-dimensional vector D, how to compute means of subsets of D + using a vector S of same size describing subset indices ? + + + .. code:: python + + # Jaime Fernández del Río + + D = np.random.uniform(0,1,100) + S = np.random.randint(0,10,100) + D_sums = np.bincount(S, weights=D) + D_counts = np.bincount(S) + D_means = D_sums / D_counts + + + Craftsman @@ -406,6 +422,7 @@ Craftsman .. code:: python # Jaime Fernández del Río + C = np.bincount([1,1,2,3,4,4,6]) A = np.repeat(np.arange(len(C)), C)