[Python] Why the dotproduct using numpy arrays result in a different value than the manually...

Discussão em 'Python' iniciado por Stack, Maio 28, 2025.

  1. Stack

    Stack Membro Participativo

    I try to learn using Numpy in Python and tried following code and compared it to a manually written code. Both should reply the same dot product.

    Here are the lines of code:

    Python lists


    arr1 = list(range(1000000))
    arr2 = list(range(1000000, 2000000))


    code

    result = 0

    for x1, x2 in zip(arr1, arr2):
    result += x1 * x2
    result


    result 833332333333500000

    Numpy arrays


    arr1_np = np.array(arr1)
    arr2_np = np.array(arr2)


    code

    np.dot(arr1_np, arr2_np)


    result -1942957984`

    I expected to get the same results as it was shown in a tutorial exactly the same way

    Continue reading...

Compartilhe esta Página