Added example
This commit is contained in:
17
README.rst
17
README.rst
@@ -364,6 +364,22 @@ Journeyman
|
|||||||
sum = A.reshape(A.shape[:-2] + (-1,)).sum(axis=-1)
|
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
|
Craftsman
|
||||||
@@ -406,6 +422,7 @@ Craftsman
|
|||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
# Jaime Fernández del Río
|
# Jaime Fernández del Río
|
||||||
|
|
||||||
C = np.bincount([1,1,2,3,4,4,6])
|
C = np.bincount([1,1,2,3,4,4,6])
|
||||||
A = np.repeat(np.arange(len(C)), C)
|
A = np.repeat(np.arange(len(C)), C)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user