In [1]:
import numpy as np

In [2]:
print(np.get_printoptions())


{'edgeitems': 3, 'threshold': 1000, 'floatmode': 'maxprec', 'precision': 8, 'suppress': False, 'linewidth': 75, 'nanstr': 'nan', 'infstr': 'inf', 'sign': '-', 'formatter': None, 'legacy': False}

In [3]:
a = np.array([12.3456, 0.123456789])
print(a)


[12.3456      0.12345679]

In [4]:
np.set_printoptions(precision=3)
print(a)


[12.346  0.123]

In [5]:
np.set_printoptions(precision=10)
print(a)


[12.3456       0.123456789]

In [6]:
np.set_printoptions(precision=4, floatmode='maxprec')
print(a)


[12.3456  0.1235]

In [7]:
np.set_printoptions(precision=10, floatmode='maxprec')
print(a)


[12.3456       0.123456789]

In [8]:
np.set_printoptions(precision=4, floatmode='fixed')
print(a)


[12.3456  0.1235]

In [9]:
np.set_printoptions(precision=10, floatmode='fixed')
print(a)


[12.3456000000  0.1234567890]

In [10]:
np.set_printoptions(precision=4, floatmode='maxprec_equal')
print(a)


[12.3456  0.1235]

In [11]:
np.set_printoptions(precision=10, floatmode='maxprec_equal')
print(a)


[12.345600000  0.123456789]

In [12]:
np.set_printoptions(precision=4, floatmode='unique')
print(a)


[12.3456       0.123456789]

In [13]:
np.set_printoptions(precision=10, floatmode='unique')
print(a)


[12.3456       0.123456789]

In [14]:
np.set_printoptions(precision=8, floatmode='maxprec')

In [15]:
b = np.round(a, 2)
print(b)


[12.35  0.12]

In [16]:
b = np.round(a, -1)
print(b)


[10.  0.]

In [17]:
b = np.round([1234.56, 123456.789], -2)
print(b)


[  1200. 123500.]

In [18]:
a = np.array([0.123456, 0.123456])
print(a)


[0.123456 0.123456]

In [19]:
a = np.array([0.123456, 0.0000123456])
print(a)


[1.23456e-01 1.23456e-05]

In [20]:
a = np.array([123.456, 0.0123456])
print(a)


[1.23456e+02 1.23456e-02]

In [21]:
np.set_printoptions(suppress=True)
print(a)


[123.456       0.0123456]

In [22]:
np.set_printoptions(suppress=True, precision=2)
print(a)


[123.46   0.01]

In [23]:
np.set_printoptions(suppress=False, precision=2)
print(a)


[1.23e+02 1.23e-02]

In [24]:
np.set_printoptions(suppress=False, precision=8, floatmode='fixed')
print(a)


[1.23456000e+02 1.23456000e-02]

In [25]:
np.set_printoptions(precision=8, floatmode='maxprec', suppress=False)

In [26]:
a = np.array([123.456, 0.0123456])
print(a)


[1.23456e+02 1.23456e-02]

In [27]:
np.set_printoptions(formatter={'float': '{:.2f}'.format})
print(a)


[123.46 0.01]

In [28]:
np.set_printoptions(formatter={'float': '{:.8f}'.format})
print(a)


[123.45600000 0.01234560]

In [29]:
np.set_printoptions(formatter={'float': '{:.2e}'.format})
print(a)


[1.23e+02 1.23e-02]

In [30]:
np.set_printoptions(formatter={'float': '{:.8e}'.format})
print(a)


[1.23456000e+02 1.23456000e-02]

In [31]:
a = np.array([12, 1234])
print(a)


[  12 1234]

In [32]:
np.set_printoptions(formatter={'int': '{:08d}'.format})
print(a)


[00000012 00001234]

In [33]:
np.set_printoptions(formatter={'int': '{:b}'.format})
print(a)


[1100 10011010010]

In [34]:
np.set_printoptions(formatter={'int': '{:o}'.format})
print(a)


[14 2322]

In [35]:
np.set_printoptions(formatter={'int': '{:x}'.format})
print(a)


[c 4d2]

In [36]:
a = np.array(['One', 'Two'])
print(a)


['One' 'Two']

In [37]:
np.set_printoptions(formatter={'numpystr': str.upper})
print(a)


[ONE TWO]

In [38]:
np.set_printoptions(formatter={'numpystr': lambda x: '***' + x + '***'})
print(a)


[***One*** ***Two***]

In [39]:
np.set_printoptions(formatter={'float': '{:0.8e}'.format, 'int': '{:08d}'.format})

In [40]:
a = np.array([12, 12.34])
print(a.dtype)
print(a)


float64
[1.20000000e+01 1.23400000e+01]

In [41]:
a = np.array([12, 123])
print(a.dtype)
print(a)


int64
[00000012 00000123]