Python | numpy.printoptions () method



Using the numpy.printoptions() method, we can get custom print options, for example, set the precision of a float value with numpy.printoptions () .

Syntax: numpy.printoptions (precision = value)
Return: Return the customized printing like precision.

Example # 1:
In this example, we can see that with numpy.printoptions () we can get individual print parameters, for example, set the exact values.

# NumPy import

import numpy as np

 
# using the numpy.printoptions () method

with np.printoptions (precision = 3 ):

print (np.array ([ 1 , 2 , 3 ]) / 2.38 )

Output:

[0.42 0.84 1.261]

Example # 2:

# NumPy import

import numpy as np

 
# using the numpy.print method options ()

with np.printoptions (precision = 5 ):

  print (np.array ([[ 5 , 10 , 15 ], [ 20 , 25 , 30 ], [ 35 , 40 , 45 ]]) / 2.3865 )

Output:

[[2.09512 4.19024 6.28536]
[8.38047 10.47559 12.57071]
[14.66583 16.76095 18.85607]]