If your array arr
has a length divisible by 3:
np.mean(arr.reshape(-1, 3), axis=1)
Reshaping to a higher dimensional array and then performing some form of reduce operation on one of the additional dimensions is a staple of numpy programming.
More Related Contents:
- Cartesian product of x and y array points into single array of 2D points
- Indexing one array by another in numpy
- Finding local maxima/minima with Numpy in a 1D numpy array
- String concatenation of two pandas columns
- How to write a multidimensional array to a text file?
- Matplotlib: save plot to numpy array
- Find column name in pandas that matches an array
- Reshape an array in NumPy
- find length of sequences of identical values in a numpy array (run length encoding)
- Is it possible to vectorize recursive calculation of a NumPy array where each element depends on the previous one?
- ImportError in importing from sklearn: cannot import name check_build
- binning data in python with scipy/numpy
- How do I count the occurrence of a certain item in an ndarray?
- Transform a set of numbers in numpy so that each number gets converted into a number of other numbers which are less than it
- Calculating Pearson correlation and significance in Python
- NumPy array initialization (fill with identical values)
- Slicing of a NumPy 2d array, or how do I extract an mxm submatrix from an nxn array (n>m)?
- Missing data, insert rows in Pandas and fill with NAN
- How to convert a .wav file to a spectrogram in python3
- Searching a sequence in a NumPy array
- How to split a numpy array in fixed size chunks with and without overlap?
- Efficient distance calculation between N points and a reference in numpy/scipy
- NumPy: Logarithm with base n
- How to display progress of scipy.optimize function?
- How to get the values from a NumPy array using multiple indices
- Fitting a Weibull distribution using Scipy
- How to use sklearn fit_transform with pandas and return dataframe instead of numpy array?
- numpy array TypeError: only integer scalar arrays can be converted to a scalar index
- Efficient dot products of large memory-mapped arrays
- mean from pandas and numpy differ