Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

python - Why does math.infinity turn to a big negative integer when overwriting in some cases?

I want to overwrite some array values for a min-finding algorithm. For these examples, I want the values of the first row to be replaced by math.inf.

It works fine in example c, but I don't understand what happens in a and b:

import numpy as np
import math

a = np.repeat(0, 9).reshape((3, 3))
a[0, :] = np.ones((3,)) * math.inf
print(a)

b = np.arange(9).reshape((3, 3))
b[0, :] = np.ones((3,)) * math.inf
print(b)

c = np.empty((3, 3))
c[0, :] = np.ones((3,)) * math.inf
print(c)

Output: shows infinity as the row entry in example c, but -9223372036854775808 in example a and b.

enter image description here

Why does the existing output have an influence when I overwrite it?

question from:https://stackoverflow.com/questions/65858232/why-does-math-infinity-turn-to-a-big-negative-integer-when-overwriting-in-some-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...