2017-10-12 82 views
1

如果我在空閒光標看到我的矩陣M價值型M,我得到:顯示用更少的數字numpy的矩陣過去小數

matrix([[ 1.65930000e+03, -2.34000000e+01, 1.50000000e+01, 
     0.00000000e+00], 
    [ 3.30000000e+00, 1.68600000e+03, -2.17000000e+01, 
     0.00000000e+00], 
    [ -1.70000000e+00, 5.00000000e+00, 1.69440000e+03, 
     0.00000000e+00], 
    [ -6.18000000e+01, 7.02000000e+01, -4.18000000e+01, 
     1.00000000e+00]]) 

用print語句形式this answer只有當我轉換工作的numpy的矩陣陣列第一:

print(np.array_str(np.array(M), precision=2))

[[ 1.66e+03 -2.34e+01 1.50e+01 0.00e+00] 
[ 3.30e+00 1.69e+03 -2.17e+01 0.00e+00] 
[ -1.70e+00 5.00e+00 1.69e+03 0.00e+00] 
[ -6.18e+01 7.02e+01 -4.18e+01 1.00e+00]] 

這是有益的,但它是很多噸的當我想要調試的時候要做些什麼。在調試過程中檢查時是否有更快速的方法來降低精度?

我也試過,但情況更糟。我喜歡科學記數法被刪除,但精度已經擴大。

print(np.array_str(M.astype(np.ndarray), precision=2))

[ matrix([[1659.2999999999988, -23.399999999999995, 14.999999999999995, 0.0]], dtype=object)] 
[ matrix([[3.3, 1686.0000000000002, -21.700000000000003, 0.0]], dtype=object)] 
[ matrix([[-1.699999999999999, 5.000000000000001, 1694.4, 0.0]], dtype=object)] 
[ matrix([[-61.799999999998704, 70.20000000000171, -41.799999999998306, 
    1.0000000000000002]], dtype=object)]] 

回答

1

NumPy的帶有輔助功能,如set_printoptions所以你可以用

numpy.set_printoptions(precision=x) 

設置的顯示精度。

+1

我沒有聽說過幫助功能。這會讓我的生活變得更好一些:-)謝謝! – uhoh