import numpy as npA = [ [1.0, 1.5, 3.0], [2.5, 13.4, 4.1], [13.4, 41.3, 5.1]]A = np.array(A)print(A)def rounder(x): if (x-int(x) >= 0.5): return np.ceil(x) else: return np.floor(x)rounder_vec = np.vectorize(rounder)whole = rounder_vec(A)print(whole)
另外,您也可以查看numpy.ceil,numpy.floor,numpy.trunc以获得其他舍入样式
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)