In [1]:
import numpy as np
In [2]:
print(np.get_printoptions())
In [3]:
a = np.array([12.3456, 0.123456789])
print(a)
In [4]:
np.set_printoptions(precision=3)
print(a)
In [5]:
np.set_printoptions(precision=10)
print(a)
In [6]:
np.set_printoptions(precision=4, floatmode='maxprec')
print(a)
In [7]:
np.set_printoptions(precision=10, floatmode='maxprec')
print(a)
In [8]:
np.set_printoptions(precision=4, floatmode='fixed')
print(a)
In [9]:
np.set_printoptions(precision=10, floatmode='fixed')
print(a)
In [10]:
np.set_printoptions(precision=4, floatmode='maxprec_equal')
print(a)
In [11]:
np.set_printoptions(precision=10, floatmode='maxprec_equal')
print(a)
In [12]:
np.set_printoptions(precision=4, floatmode='unique')
print(a)
In [13]:
np.set_printoptions(precision=10, floatmode='unique')
print(a)
In [14]:
np.set_printoptions(precision=8, floatmode='maxprec')
In [15]:
b = np.round(a, 2)
print(b)
In [16]:
b = np.round(a, -1)
print(b)
In [17]:
b = np.round([1234.56, 123456.789], -2)
print(b)
In [18]:
a = np.array([0.123456, 0.123456])
print(a)
In [19]:
a = np.array([0.123456, 0.0000123456])
print(a)
In [20]:
a = np.array([123.456, 0.0123456])
print(a)
In [21]:
np.set_printoptions(suppress=True)
print(a)
In [22]:
np.set_printoptions(suppress=True, precision=2)
print(a)
In [23]:
np.set_printoptions(suppress=False, precision=2)
print(a)
In [24]:
np.set_printoptions(suppress=False, precision=8, floatmode='fixed')
print(a)
In [25]:
np.set_printoptions(precision=8, floatmode='maxprec', suppress=False)
In [26]:
a = np.array([123.456, 0.0123456])
print(a)
In [27]:
np.set_printoptions(formatter={'float': '{:.2f}'.format})
print(a)
In [28]:
np.set_printoptions(formatter={'float': '{:.8f}'.format})
print(a)
In [29]:
np.set_printoptions(formatter={'float': '{:.2e}'.format})
print(a)
In [30]:
np.set_printoptions(formatter={'float': '{:.8e}'.format})
print(a)
In [31]:
a = np.array([12, 1234])
print(a)
In [32]:
np.set_printoptions(formatter={'int': '{:08d}'.format})
print(a)
In [33]:
np.set_printoptions(formatter={'int': '{:b}'.format})
print(a)
In [34]:
np.set_printoptions(formatter={'int': '{:o}'.format})
print(a)
In [35]:
np.set_printoptions(formatter={'int': '{:x}'.format})
print(a)
In [36]:
a = np.array(['One', 'Two'])
print(a)
In [37]:
np.set_printoptions(formatter={'numpystr': str.upper})
print(a)
In [38]:
np.set_printoptions(formatter={'numpystr': lambda x: '***' + x + '***'})
print(a)
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)
In [41]:
a = np.array([12, 123])
print(a.dtype)
print(a)