Numpy calculations not computing correctly

Consider these lines of code:

    y[:,:,i,p] = np.divide(x[:,:,i,p], npq)   #divide array by constant
    orig =[:,:,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:


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.

Assuming npq is a scalar constant, this is enough.

y[:,:,i,p] /= npq  # division


y[:,:,i,p] *= npq  # multiplication should not be used unless you are performing matrix multiplication on tensors.