-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Interface to multi-apply * update documentation, README Co-authored-by: jkanche <[email protected]>
- Loading branch information
1 parent
ccec946
commit c68334c
Showing
11 changed files
with
257 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Contributors | ||
|
||
* jkanche <[email protected]> | ||
* [Jayaram Kancherla](https://github.com/jkanche) <[email protected]> | ||
* [Victor Alexandru](https://github.com/VictorAlex1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Changelog | ||
|
||
|
||
## Version 0.2.0 | ||
- Support multi apply | ||
|
||
## Version 0.1 (development) | ||
|
||
- first release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Tutorial | ||
|
||
## Sample data | ||
|
||
For the purpose of this, lets generate a test matrix and groups | ||
|
||
```python | ||
from mopsy import colsum | ||
import random from rd | ||
# generate a random sparse array with some density | ||
from scipy.sparse import random | ||
mat = random(10, 150, 0.25) | ||
|
||
# generate random groups | ||
ngrps = 15 | ||
gsets = [x for x in range(15)] | ||
groups = [rd.choice(gsets) for x in range(mat.shape[axis])] | ||
``` | ||
|
||
## apply a function along an axis | ||
|
||
Methods are available to perform `sum`, `median`, `mean` along any axis. | ||
|
||
To apply any of these methods | ||
|
||
```python | ||
colsum(mat, groups) | ||
``` | ||
|
||
# Bring your own function | ||
|
||
`mopsy` provides a generic `apply` method is also available for perform row-wise or column-wise operations. | ||
|
||
lets define our own function to count the number of non-zero elements in the array | ||
|
||
```python | ||
import numpy as np | ||
|
||
def nz_func(arr): | ||
return np.count_nonzero(arr) | ||
``` | ||
|
||
now lets apply the function, | ||
|
||
```python | ||
from mopsy import multi_apply | ||
|
||
apply(nz_func, mat, axis=1) | ||
``` | ||
|
||
## Multiple functions | ||
|
||
`mopsy` also supports multiple functions. | ||
|
||
```python | ||
from mopsy import multi_apply | ||
import numpy as np | ||
|
||
multi_apply([np.sum, np.mean], mat, axis=0) | ||
``` | ||
|
||
That's all for today! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.