Python Numpy matrix.round()
在Numpy matrix.round()方法的帮助下,我们能够对给定矩阵的数值进行四舍五入。
语法: 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.]]