Skip to content

Commit a4491d1

Browse files
committed
Added example
1 parent e207cb1 commit a4491d1

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

README.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,22 @@ Journeyman
364364
sum = A.reshape(A.shape[:-2] + (-1,)).sum(axis=-1)
365365
366366
367+
7. Considering a one-dimensional vector D, how to compute means of subsets of D
368+
using a vector S of same size describing subset indices ?
369+
370+
371+
.. code:: python
372+
373+
# Jaime Fernández del Río
374+
375+
D = np.random.uniform(0,1,100)
376+
S = np.random.randint(0,10,100)
377+
D_sums = np.bincount(S, weights=D)
378+
D_counts = np.bincount(S)
379+
D_means = D_sums / D_counts
380+
381+
382+
367383
368384
369385
Craftsman
@@ -406,6 +422,7 @@ Craftsman
406422
.. code:: python
407423
408424
# Jaime Fernández del Río
425+
409426
C = np.bincount([1,1,2,3,4,4,6])
410427
A = np.repeat(np.arange(len(C)), C)
411428

0 commit comments

Comments
 (0)