Skip to content

Instantly share code, notes, and snippets.

@gdementen
Last active July 29, 2016 08:19
Show Gist options
  • Save gdementen/64cfa3eb5ca5aebd460fe338510c84c1 to your computer and use it in GitHub Desktop.
Save gdementen/64cfa3eb5ca5aebd460fe338510c84c1 to your computer and use it in GitHub Desktop.
Strange sum
>>> l = [4873.40374783,
5821.07686377,
5781.99852348,
5555.53769711,
0.0,
0.0,
0.0,
0.0]
>>> a = np.array(l)
>>> b = np.empty((8, 2))
>>> b[:] = a[:, np.newaxis]
>>> b
array([[ 4873.40374783, 4873.40374783],
[ 5821.07686377, 5821.07686377],
[ 5781.99852348, 5781.99852348],
[ 5555.53769711, 5555.53769711],
[ 0. , 0. ],
[ 0. , 0. ],
[ 0. , 0. ],
[ 0. , 0. ]])
>>> b.sum(0)[0] == b[:,0].sum()
False
>>> b.sum(0)[0]
22032.016832190002
>>> b[:,0].sum()
22032.016832189998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment