📜  Python| numpy matrix.round()

📅  最后修改于: 2022-05-13 01:54:33.529000             🧑  作者: Mango

Python| numpy matrix.round()

Numpy matrix.round()方法的帮助下,我们能够对给定矩阵的值进行四舍五入

示例 #1:

在给定的示例中,我们可以使用matrix.round()方法对给定的矩阵进行四舍五入。

# import the important module in python
import numpy as np
           
# make matrix with numpy
gfg = np.matrix('[6.4, 1.3; 12.7, 32.3]')
           
# applying matrix.round() method
geeks = gfg.round()
     
print(geeks)
输出:
[[  6.   1.]
 [ 13.  32.]]


示例 #2:

# import the important module in python
import numpy as np
           
# make a matrix with numpy
gfg = np.matrix('[1.2, 2.3; 4.7, 5.5; 7.2, 8.9]')
           
# applying matrix.round() method
geeks = gfg.round()
     
print(geeks)
输出:
[[ 1.  2.]
 [ 5.  6.]
 [ 7.  9.]]