3
I’ve always used the method np.prod
as a production operator. So if I want to know the factorial of 5, for example, I simply do:
import numpy as np
np.prod([5,4,3,2,1])
120
It turns out I was working today and I noticed an inconsistency in this procedure. I was counting the number of possible combinations of 12 people having their birthday on different days. Following my interpretation of np.prod
done:
np.prod([365,364,363,362,361,360,359,358,357,356,355,354])
4433906698518895616
This value is wrong. The correct is obtained in the expression:
365*364*363*362*361*360*359*358*357*356*355*354
4657431227433109900901013888000
Why the np.prod
returned the wrong result? How does this method work?
Isn’t it because of the overflow? A documentation says: "Arithmetic is modular when using integer types, and no error is Raised on overflow" - see also https://stackoverflow.com/q/39089618
– hkotsubo