How to print a numpy.array in one line?

后端 未结 3 1116
感动是毒
感动是毒 2021-02-19 18:34

I tested PyCharm and IDLE, both of them print the 7th number to a second line.

Input:

import numpy as np
a=np.array([ 1.02090721,  1.02763091,  1.038993         


        
3条回答
  •  甜味超标
    2021-02-19 19:23

    If you want a customized version of str(a), the answer is array_str:

    >>> print(a)
    [ 1.02090721  1.02763091  1.03899317  1.00630297  1.00127454  0.89916715
      1.04486896]
    >>> str(a)
    '[1.02090721 1.02763091 1.03899317 1.00630297 1.00127454 0.89916715\n 1.04486896]'
    >>> np.array_str(a, max_line_width=np.inf)
    '[1.02090721 1.02763091 1.03899317 1.00630297 1.00127454 0.89916715 1.04486896]'
    >>> print(np.array_str(a, max_line_width=np.inf)
    [1.02090721 1.02763091 1.03899317 1.00630297 1.00127454 0.89916715 1.04486896]
    

    If you want to change the printout of every array, not just here, see set_printoptions.

提交回复
热议问题