Saturday, December 28, 2024
Google search engine
HomeLanguagesPython | numpy.printoptions() method

Python | numpy.printoptions() method

With the help of numpy.printoptions() method, we can get the custom printing options like we can set the precisions of floating value by using numpy.printoptions() method.

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

Example #1 :
In this example we can see that by using numpy.printoptions() method, we are able to get the customized printing options like we can set the precision values.




# import numpy
import numpy as np
  
# using 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 :




# import numpy
import numpy as np
  
# using numpy.printoptions() method
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]]

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments