I’m trying to normalize some values in a numpy array with the following shape:
import numpy as np
X = np.random.rand(100, 20, 3)
This data says there are 100 time stamps for each of 20 observations, where each observation has 3 dimensional attributes (x, y, z). I want to normalize the x, y, z dimensional attributes in the following way. For each dimension, I want to subtract the min then divide by the resulting max (to “center” the dimension’s values).
I attempted to do this with the following:
# center all features
for i in range(3):
X[:][:][i] -= np.min(X[:][:][i])
X[:][:][i] /= np.max(X[:][:][i])
This does not mutate all values of the ith dimension, however.
How can I center my features in this way? Any help others can offer would be greatly appreciated!
X[:][:][i]is multi-dimensional indexing in numpy. Shouldn't it beX[:, :, i]? I can't test atm.ith dimension" What do you mean by that? Could you please clarify?ithindex in the last dimension will be mutated. Here i is an index into the 3 dimensional space (the third of the values provided byX.shape). Sorry my language here is kind of clunky.