Skip to content
Related Articles

Related Articles

Improve Article

Python | numpy.printoptions() method

  • Last Updated : 03 Oct, 2019

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]]

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :