Python Forum
numpy.dot() result different with classic computation for large-size arrays
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numpy.dot() result different with classic computation for large-size arrays
#2
I guess it is because a 64 bits signed integer can store values between -2**63 and +2**63-1, which order of magnitude is 10**19, but here the result has a magnitude of 10**23. It follows that some bits are silently lost by overflow in the computation with 64 bits integers. Here is an example
>>> import array
>>> a = array.array('q')
>>> x = 2**63-1000
>>> x
9223372036854774808
>>> a.append(x)
>>> a
array('q', [9223372036854774808])
>>> import numpy as np
>>> np.dot(a, a)
1000000
>>> x * x
85070591730234597419099578148391436864
>>>
Reply


Messages In This Thread
RE: numpy.dot() result different with classic computation for large-size arrays - by Gribouillis - Jan-25-2022, 08:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Converted EXE file size is too large Rajasekaran 0 1,601 Mar-30-2023, 11:50 AM
Last Post: Rajasekaran
  problem adding two numpy arrays djf123 2 2,165 Aug-09-2022, 08:31 PM
Last Post: deanhystad
  how to join by stack multiple types in numpy arrays caro 1 1,190 Jun-20-2022, 05:02 PM
Last Post: deanhystad
  Element wise computation divon 2 1,672 Jun-01-2022, 02:36 AM
Last Post: divon
  How do I read in a Formula in Excel and convert it to do the computation in Python? JaneTan 2 2,758 Jul-07-2021, 02:06 PM
Last Post: Marbelous
  Two numpy arrays Sandra2312 1 1,849 Jan-18-2021, 06:10 PM
Last Post: paul18fr
  numpy in1d with two simple arrays claw91 3 2,660 Sep-21-2020, 12:43 PM
Last Post: scidam
  Type coercion with Numpy arrays Mark17 2 2,593 Jul-24-2020, 02:04 AM
Last Post: scidam
  filling and printing numpy arrays of str pjfarley3 4 3,428 Jun-07-2020, 09:09 PM
Last Post: pjfarley3
  size of set vs size of dict zweb 0 2,205 Oct-11-2019, 01:32 AM
Last Post: zweb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020