Im trying to ensure each row has zero mean for a matrix of arbitrary dimensions. However Im getting IndexError: index 2 is out of bounds for axis 0 with size 2 when running the code below. Im iterating over values within the dimensions of Z only so I don't see how I could be attempting to index outside the dimensions of Z.
import numpy as np
def center_rows(Z):
"""Ensures each row has zero mean.
Takes a matrix of arbitrary shape and subtracts from each row the mean value of that row."""
Zc = Z
for row in Z:
avg = np.mean(Z[row])
Zc[row] = Z[row] - avg
return Zc
Z = [[1,2,3], [4,5,6]]. The firstrow == [1,2,3]. DoesZ[row]make sense? It may make sense for multidimensional NumPy arrays, but is it what you really want? - ForceBru