Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
>>> x array([[ 0, 2, 3, 4], [ 6, 0, 8, 9], [ 1, 2, 0, -9] [ -9, 4, 3, 0])
我希望能够将 -9 识别为 min(x),而不是 0。
谢谢
将对角线设置为其 的最大值dtype。对于浮点类型,那将是np.inf,但对于整数,您必须更加努力。
dtype
np.inf
x[np.diag_indices_from(x)] = np.iinfo(x.dtype).max
采取min.
min
将对角线设置回零。
Since -9 < 0 x.min() should work without any trickery. You only need to worry if you min won't be negative.
-9 < 0 x.min()