Skip to content

Instantly share code, notes, and snippets.

@beatorizu
Last active June 10, 2018 21:27
Show Gist options
  • Select an option

  • Save beatorizu/d03a7585f8306602fae647e6aee58293 to your computer and use it in GitHub Desktop.

Select an option

Save beatorizu/d03a7585f8306602fae647e6aee58293 to your computer and use it in GitHub Desktop.
Aplicar função de acordo com o eixo e cortes por intervalo
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