I have the following code:
import numpy as np
NV = np.sum(A[:, 0]*A[:, 1])
V = np.dot(np.reshape(A[:, 0], (1, -1)), A[:, 1])
EFL = 0
for i in range(len(A[:, 0])):
EFL += A[i, 0]*A[i, 1]
where the A is a two dimensional array. So basically, I am multiplying two columns of A element-wise and then adding the results, and I am expecting that these three methods have the same results. However, the results are very different.
For the non-vectorized NV, the result is 1.7763568394002505e-14, the vectorized V is 2.22599716e-14, and the explicit for-loop EFL is 9.272096979096034e-14.
I have tried multiplying a column of A by itself, effectively an A[:, 0]^2, and the results are almost the same, 1107.1945737348647, 1107.19457373, and 1107.1945737348658 for the NV, V, and EFL, respectively.
Another test that I did was to perform the same calculation (i.e. the different columns of A) in Microsoft Excel, and that too gives a different result (around 2.10e-13). Another strange thing that I encountered was that the results are almost the same up to the second last element of A, and they become different once I include the last element. I have checked the last element of A and is no different from the other numbers in the array. What could be wrong here?
Thank you in advance.
Here is the link to the matrix A: https://drive.google.com/file/d/16bmI3lg8-2pUntmxtLiaE0cAuvMfhjcj/view?usp=sharing
The numpy version I am using, if it is somehow related is 1.19.2.