How to avoid less precise sum for numpy-arrays with multiple columns
I've always assumed, that numpy uses a kind of pairwise-summation , which ensures high precision also for float32 - operations: import numpy as np N=17*10**6 # float32-precision no longer enough to hold the whole sum print(np.ones((N,1),dtype=np.float32).sum(axis=0)) # [17000000.], kind of expected However, it looks as if a different algorithm is used if the matrix has more than one column: print(np.ones((N,2),dtype=np.float32).sum(axis=0)) # [16777216. 16777216.] the error is just to big print(np.ones((2*N,2),dtype=np.float32).sum(axis=0)) # [16777216. 16777216.] error is bigger Probably sum