Last active
June 10, 2018 21:27
-
-
Save beatorizu/d03a7585f8306602fae647e6aee58293 to your computer and use it in GitHub Desktop.
Aplicar função de acordo com o eixo e cortes por intervalo
This file contains hidden or 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
| import numpy as np | |
| data = np.random.rand(7, 3, 2) | |
| op_dict = {'sum': np.sum, 'mean': np.mean, 'max': np.max, 'min': np.min} | |
| def apply_function(func, data, step, axis=0, slice_=slice(None)): | |
| sections = np.arange(step, data.shape[axis], step) | |
| return np.array([func(d[slice_], axis=axis) for d in np.split(data, sections, axis=axis)]) | |
| apply_function(op_dict['sum'], data, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment