Consider these lines of code:
y[:,:,i,p] = np.divide(x[:,:,i,p], npq) #divide array by constant orig = np.dot(y[:,:,i,p], npq) #take previous output, and multiply by constant print(np.mean(x[:,:,i,p] - orig)) #print mean. should be 0
The expected output of these calculations should be 0. Rather, i'm getting the following:
... 0.0 -1.81671383445 -0.0719097733101 -0.102587446807 ...
What am I doing wrong? I've tried converting all the numbers to integers rather than floating points, and the errors persist.
If you're going to be doing arithmetic involving constants, I'd recommend sticking to broadcasting.
npq is a scalar constant, this is enough.
y[:,:,i,p] /= npq # division
y[:,:,i,p] *= npq # multiplication
np.dot should not be used unless you are performing matrix multiplication on tensors.