w3resource

NumPy: Suppresses the use of scientific notation for small numbers in NumPy array

NumPy: Array Object Exercise-84 with Solution

Write a NumPy program to suppresses the use of scientific notation for small numbers in NumPy array.

Sample Solution:-

Python Code:

import numpy as np
x=np.array([1.6e-10, 1.6, 1200, .235]) 
print("Original array elements:")
print(x)
print("Print array values with precision 3:")
np.set_printoptions(suppress=True)
print(x)

Sample Output:

Original array elements:
[1.60e-10 1.60e+00 1.20e+03 2.35e-01]
Print array values with precision 3:
[   0.       1.6   1200.       0.235]

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to display NumPy array elements of floating values with given precision.
Next: Write a NumPy program to create a NumPy array of 10 integers from a generator.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Set comprehension:

>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}