Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:将整数矩阵转换为小数矩阵_Python_Python 3.x_Matrix_Python Decimal - Fatal编程技术网

Python:将整数矩阵转换为小数矩阵

Python:将整数矩阵转换为小数矩阵,python,python-3.x,matrix,python-decimal,Python,Python 3.x,Matrix,Python Decimal,我有一个Python矩阵,由于代码后面部分的舍入问题,我想将其转换为Decimal元素的矩阵。我在用蟒蛇3。我该怎么做 我的矩阵是 a = [ [0, 9, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1], [1, 1, 1, 0] ] 类似于给出错误的b=Decimal(a)。根据Denis Rasulev的精彩评论,这可以通过 b = [[Decimal(i) for i in j] for j in a] 这个答案有用吗?是的,太好了

我有一个Python矩阵,由于代码后面部分的舍入问题,我想将其转换为
Decimal
元素的矩阵。我在用蟒蛇3。我该怎么做

我的矩阵是

a = [
    [0, 9, 1, 1],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
    [1, 1, 1, 0]
]

类似于给出错误的
b=Decimal(a)

根据Denis Rasulev的精彩评论,这可以通过

b = [[Decimal(i) for i in j] for j in a]

这个答案有用吗?是的,太好了,谢谢!