Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing float precision precision in numpy jupyter notebook

I want to print floats with precision 4. I use numpy , jupyter notebook I tried:

%precision %.4g
%precision 2
np.set_printoptions(precision=2)
print(0.6776776)

the output:

0.6776776

Any Ideas what is wrong ?

# 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       
like image 956
Naomi Fridman Avatar asked Sep 24 '18 10:09

Naomi Fridman


1 Answers

Print does not care about numpy or IPython formatters. It calls str() in the Background, any formatting has to be done using Standard print formatters (%.2f and the like). Look at the different Output for:

%precision 3
a = 0.6776776
print(a)
a

The result will be:

0.6776776
0.678
like image 198
Rriskit Avatar answered Nov 14 '22 10:11

Rriskit