gpt4 book ai didi

python - Numpy.linalg.det()返回错误的结果

转载 作者:行者123 更新时间:2023-12-03 09:07:56 26 4
gpt4 key购买 nike

谁知道Numpy为什么返回“-2.0000000000000004”而不是“-2”

>>> M = [[1,2],[3,4]]
>>> numpy.linalg.det(M)
-2.0000000000000004

我正在使用Python 3.4.2(x64),Numpy 1.9.1和Windows 7 x64。

最佳答案

使用带有第二个参数的round作为2(或根据需要)
例:

M = [[1,2],[3,4]]

print ( numpy.linalg.det(M) ) # -2.0000000000000004

print ( round(numpy.linalg.det(M),2) ) # -2.0

关于python - Numpy.linalg.det()返回错误的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27327526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com