1. 程式人生 > >令矩陣每個元素四舍五入,使順序高斯與列主元高斯結果不同

令矩陣每個元素四舍五入,使順序高斯與列主元高斯結果不同

dex 實現 for in index 思路 return 四舍五入 .sh sha

實現思路就是在每次循環中對矩陣進行四舍五入處理

實現代碼如下

# 四舍五入
def matrixRound(M, decPts=5):
    # 對行循環
    for index in range(M.shape[0]):
        # 對列循環
        for _index in range(M.shape[1]):
            M[index, _index] = round(M[index, _index], decPts)

    return M

  

令矩陣每個元素四舍五入,使順序高斯與列主元高斯結果不同