寻找分钟在列表/ 2D数组中并在Python中进行计算

我有一个清单,我想找到分钟。每行中的值并进行计算:row-row.min-1。

这是我尝试过的

import numpy as np

list = [[1.2886089553007253e-15, 3.283665029781338e-16, 0.0, 3.4027301260438933e-16],\
        [3.047580716284324e-15, 1.3787915767152193e-15, 3.505982818951592e-16, 0.0]]

array = np.asarray(list)

result = array-array.min(axis=0)-1

print(result)

这是我得到的结果,

[[-1. -1. -1. -1.]
 [-1. -1. -1. -1.]]

但我希望得到

[[1.2886089553007253e-15 -0.0-1, 3.283665029781338e-16 -0.0-1, 0.0 -0.0-1, 3.4027301260438933e-16 -0.0-1], 
[3.047580716284324e-15 -0.0-1, 1.3787915767152193e-15 -0.0-1, 3.505982818951592e-16 -0.0-1, 0.0 -0.0-1]]

原来如此

[[-0.9999999999999987, -0.9999999999999997, -1, -0.9999999999999997],
 [-0.999999999999997, -0.9999999999999987, -0.9999999999999997, -1]]

我该怎么做?

评论
哎呦喂
哎呦喂

您已经有了正确的值-您只是没有以足够的精度打印它们:

import numpy as np
# set the printout precision
np.set_printoptions(precision=20)
list = [[1.2886089553007253e-15, 3.283665029781338e-16, 0.0, 3.4027301260438933e-16],\
        [3.047580716284324e-15, 1.3787915767152193e-15, 3.505982818951592e-16, 0.0]]

array = np.asarray(list)

result = array-array.min(axis=0)-1

print(result)

输出:

[[-1.                 -1.                 -1.                  -0.9999999999999997]
 [-0.9999999999999982 -0.999999999999999  -0.9999999999999997  -1.                ]]

See numpy.set_printoptions

点赞
评论