Nao*_*man 6 python precision numpy jupyter-notebook
我想以 4 精度打印浮点数。我使用 numpy ,我尝试过的 jupyter notebook:
%precision %.4g
%precision 2
np.set_printoptions(precision=2)
print(0.6776776)
输出:
0.6776776
任何想法有什么问题?
# Name                    Version                   
ipython                   6.4.0                    
ipython_genutils          0.2.0            
msgpack-python            0.5.6            
python                    3.6.5                
python-dateutil           2.7.3       
Print 不关心 numpy 或 IPython 格式化程序。它在后台调用 str(),任何格式化都必须使用标准打印格式化程序(%.2f 等)来完成。查看不同的输出:
%precision 3
a = 0.6776776
print(a)
a
结果将是:
0.6776776
0.678