python - How to printing numpy array with 3 decimal places? -


how can print numpy array 3 decimal places? tried array.round(3) keeps printing 6.000e-01. there option make print this: 6.000?

i got 1 solution print ("%0.3f" % arr), want global solution i.e. not doing every time want check array contents.

 np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)}) 

this set numpy use lambda function formatting every float prints out.

other types can define formatting (from docstring of function)

    - 'bool'     - 'int'     - 'timedelta' : `numpy.timedelta64`     - 'datetime' : `numpy.datetime64`     - 'float'     - 'longfloat' : 128-bit floats     - 'complexfloat'     - 'longcomplexfloat' : composed of 2 128-bit floats     - 'numpy_str' : types `numpy.string_` , `numpy.unicode_`     - 'str' : other strings  other keys can used set group of types @ once are::      - 'all' : sets types     - 'int_kind' : sets 'int'     - 'float_kind' : sets 'float' , 'longfloat'     - 'complex_kind' : sets 'complexfloat' , 'longcomplexfloat'     - 'str_kind' : sets 'str' , 'numpystr' 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

angularjs - ng-repeat duplicating items after page reload -