How to force a ndarray show in normal way instead of scientific notation?

后端 未结 2 1547
难免孤独
难免孤独 2021-01-13 16:21

I\'m trying to print a ndarray on the screen. But python always shows it in scientific notation, which I don\'t like. For a scalar we can use

>>> p         


        
相关标签:
2条回答
  • 2021-01-13 16:32

    The numpy.set_string_function function can be used to change the string representation of arrays.

    You can also use numpy.set_print_options to change the precision used by default and turn off reporting of small numbers in scientific notation.

    From the examples for set_print_options:

    >>> np.set_printoptions(precision=4)
    >>> print np.array([1.123456789])
    [ 1.1235]
    
    0 讨论(0)
  • 2021-01-13 16:38

    I don't know about the numpy arrays but I was simply facing the same problem while doing a project in Python.

    Take a look at the Decimal class provided http://docs.python.org/library/decimal.html .

    I don't know if it's provided in numpy though.

    0 讨论(0)
提交回复
热议问题