Skip to content

Commit

Permalink
example axis
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilJl committed May 28, 2024
1 parent d5195ed commit 249d31e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ np.allclose(true_cov, batchcov()), batchcov().shape
>>> (True, (100, 50))
```

`batchstats` is also flexible in terms of input shapes, with the first dimension always representing the samples and the remaining dimensions representing the features:
`batchstats` is also flexible in terms of input shapes. By default, statistics are applied on the first axis: the first dimension representing the samples and the remaining dimensions representing the features:

```python
import numpy as np
Expand All @@ -80,6 +80,27 @@ np.allclose(true_sum, batchsum()), batchsum().shape
>>> (True, (80, 90))
```

But as in the ``numpy`` associated functions, the user can specify the reduction axis or axes:

```python
import numpy as np
from batchstats import BatchMean

data = [np.random.randn(24, 7, 128) for _ in range(100)]

batchmean = BatchMean(axis=(0, 2))
for batch in data:
batchmean.update_batch(batch)
batchmean().shape
>>> (7,)

batchmean = BatchMean(axis=2)
for batch in data:
batchmean.update_batch(batch)
batchmean().shape
>>> (24, 7)
```

## Available Classes/Stats

- `BatchCov`: Compute the covariance matrix of two datasets (not necessarily square)
Expand Down

0 comments on commit 249d31e

Please sign in to comment.