← numpy-100

Added example

a4491d1ed6a3a709f64ace573a6b874b2c9aae85 · Nicolas Rougier · May 27, 2014 06:50

+17 · 1 file changed

  • README.rst +17 −0
diff --git a/README.rst b/README.rst
index 4ad66c6..2de2521 100644
--- a/README.rst
+++ b/README.rst
@@ -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)