Home>
% precision does not work in certain cases in jupyter notebook

This is something i am learning using the jupyter notebook.
If i execute the magic command as follows, pi will be up to the decimal point 3.
The calculation result of numpy is a situation where the notation of the decimal point does not change.
Could you tell me how to solve it?

Source code and output
[in1]
import numpy as np
from math import pi
[in2]
% precision 3
[out2]
'% .3f'
[in3]
pi
[out3]
3.142
[in4]
scores = np.array ([30, 40, 100])
std = np.sqrt (np.var (scores, ddof = 0))
std
[out4]
30.912061651652348
np.set_printoptions (precision = 3)

I tried the above but did not improve it.

Version

python 3.7.3
jupyter 1.0.0
numpy 1.16.4

  • Answer # 1

    https://github.com/numpy/numpy/issues/11048
    There is a link from https://github.com/numpy/numpy/pull/9201#issuecomment-332609336 ↑.

    It seems similar to what is discussed in

    .

    Whenstrorreprfunction is applied to

    numpy.float64, the result should behave in the same way as the built-in Python float type Since it seems to be based on a philosophy, I don't think there is any means (you can only format it yourself).


    (Added)

    I had to find out if there was a way to write numpy.float64 for jupyter.
    Please forgive me for half the answer.