I'm getting: /usr/local/cpython-2.7/bin/python (2.7.16) bad ('numpy version:', '1.16.6') Traceback (most recent call last): File "./nii", line 31, in <module> assert left == right, "{} != {}".format(left, right) AssertionError: 86374.0371429 != 86374.0371429 /usr/local/cpython-3.0/bin/python (3.0.1) bad No numpy found /usr/local/cpython-3.1/bin/python (3.1.5) bad No numpy found /usr/local/cpython-3.2/bin/python (3.2.5) bad No numpy found /usr/local/cpython-3.3/bin/python (3.3.7) bad No numpy found /usr/local/cpython-3.4/bin/python (3.4.8) bad No numpy found /usr/local/cpython-3.5/bin/python (3.5.5) bad numpy version: 1.18.5 Traceback (most recent call last): File "./nii", line 31, in <module> assert left == right, "{} != {}".format(left, right) AssertionError: 86374.03714285714 != 86374.03714285715 /usr/local/cpython-3.6/bin/python (3.6.0) bad numpy version: 1.18.1 Traceback (most recent call last): File "./nii", line 31, in <module> assert left == right, "{} != {}".format(left, right) AssertionError: 86374.03714285714 != 86374.03714285715 /usr/local/cpython-3.7/bin/python (3.7.0) bad numpy version: 1.19.0 Traceback (most recent call last): File "./nii", line 31, in <module> assert left == right, "{} != {}".format(left, right) AssertionError: 86374.03714285714 != 86374.03714285715 /usr/local/cpython-3.8/bin/python (3.8.0) bad numpy version: 1.19.0 Traceback (most recent call last): File "./nii", line 31, in <module> assert left == right, "{} != {}".format(left, right) AssertionError: 86374.03714285714 != 86374.03714285715 /usr/local/cpython-3.9/bin/python (3.9.0) bad numpy version: 1.19.4 Traceback (most recent call last): File "/home/dstromberg/src/stack-overflow,python-list/numpy-initial-incidence/./nii", line 31, in <module> assert left == right, "{} != {}".format(left, right) AssertionError: 86374.03714285714 != 86374.03714285715
So the difference is tiny for me, and can be imputed to rounding error. Multiplying the big terms first before dividing naturally gives less rounding error. As far as why your install is having problems, I don't really know. What version of numpy are you using? On Wed, Feb 24, 2021 at 12:12 PM Carla Molina <carlamolinagr...@gmail.com> wrote: > I found the following bug (python 3.9.1) when multiplying an array by > several variables without parentheses; look at the following example: > > import numpy as np > > NR = 0.25 > N = 60461826 > > initialINCIDENCE = np.array([1, 50, 100, 150, 200, 250, 300]) > initialINCIDENCE = initialINCIDENCE*N/(100000*7*NR) > print('First result ' +str(initialINCIDENCE)) > > initialINCIDENCE = np.array([1, 50, 100, 150, 200, 250, 300]) > initialINCIDENCE = initialINCIDENCE*(N/(100000*7*NR)) > print('Second result ' +str(initialINCIDENCE)) > > The result given is: > > First result [ 345.49614857 -7267.86283429 10006.94459429 2739.08176 > -4528.78107429 -11796.64390857 5478.16352 ] > Second result [ 345.49614857 17274.80742857 34549.61485714 > 51824.42228571 69099.22971429 86374.03714286 103648.84457143] > > Clearly both are different, and in particular the first one has no sense to > me. > Thank you, > > Carla. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list