numpy 数据运算操作
1.np.around
np.around返回四舍五入后的值,可以指定精度
格式:
- around(a, decimals=0, out=None)
decimal表示精度,整数表示小数点右边保留几位,负数表示小数点左边保留几位
import numpy as np
a = [np.random.normal(10) for _ in range(10)]
# [8.75979108665653,
#9.381251593781995,
# 9.26005756259318,
# 11.703953107247258,
# 9.99876118043351,
# 9.721232175215642,
# 10.2967504704746,
#10.222862901423143,
# 10.30046520090437,
# 10.677490944692005]
np.around(a)
# array([ 9., 9., 9., 12., 10., 10., 10., 10., 10., 11.])
np.around(a,decimals=-1,out=None)
# 说明
#Out[16]: array([10., 10., 10., 10., 10., 10., 10., 10., 10., 10.])
np.around(a,decimals=-2,out=None)
# 说明
#Out[17]: array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
2. np.floor
返回不大于输入参数的最大整数,即向前取整,输入为x,将返回大于x的整数i,i<=x,都往小处走。
n = np.array([-1.7,