简体   繁体   English

由矩阵计算得出的numpy数组中的值取整

[英]Rounding values in a numpy array resulting from matrix calculation

I have some calculation involving two matrices both represented in numpy arrays. 我有一些涉及两个矩阵的计算,两个矩阵都表示为numpy数组。

After the calculation, i obtain a vector of floats represented in another numpy array. 在计算之后,我获得了另一个numpy数组中表示的floats向量。

I want to round up/down the values in this resultant vector, eg if the calculation gives: 我想向上/向下舍入此结果向量中的值,例如,如果计算给出:

array([1.33333, 2.56, 9.99999, 16.0])

then it should be rounded to: 那么它应该舍入到:

array([1, 3, 10, 16])

What is the fastest way to do this? 最快的方法是什么?

NumPy arrays have a round method: NumPy数组有一个圆形方法:

In [73]: x = np.array([1.33333, 2.56, 9.99999, 16.0])

In [74]: x.round()
Out[76]: array([  1.,   3.,  10.,  16.])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM