I have recently applied this solution for averaging every N rows of matrix.
Although the solution works in general I had problems when applied to a 7x1 array. I have noticed that the problem is when using the -=
operator.
To make a small example:
import numpy as np
a = np.array([1,2,3])
b = np.copy(a)
a[1:] -= a[:-1]
b[1:] = b[1:] - b[:-1]
print a
print b
which outputs:
[1 1 2]
[1 1 1]
So, in the case of an array a -= b
produces a different result than a = a - b
. I thought until now that these two ways are exactly the same. What is the difference?
How come the method I am mentioning for summing every N rows in a matrix is working e.g. for a 7x4 matrix but not for a 7x1 array?