m2 = np.average(m, 0)
vals = np.zeros(N)
for i in range(N):
    u = nhat[i]
if u[0] >= 0 and u[1] >= 0 and u[2] >= 0:
    vals[i] = abs(np.dot(u, m2))
else:
    for j in range(M):
        vals[i] += abs(np.dot(u, m[j]))
vals[i] /= M
Non-trivial sums of outer products without temporaries in numpy