Print a NumPy Array Without Scientific Notation in Python
Last Updated :
28 Apr, 2025
We have given you a Numpy array. We are going to display the Numpy array without scientific notation and with the given precision. In this article, we are going to explore different methods in Python.
Example
Input 1: Array = [123.456, 0.123456, 987.123] , Precision = 2
Output 1: [123.46 0.12 987.12]
Input 2: Array = [123.456, 0.123456, 987.123] , Precision = 3
Output 2: [123.456 0.123 987.123]
Print a NumPy Array Without Scientific Notation in Python
Below are the methods that are used to Print a NumPy Array Without Scientific Notation:
- Using set_printoptions() with suppress, and precision as parameters.
- Using set_printoptions() with .foramt()
- Using array_str()and
Using set_printoptions() with suppress, and precision as parameters
Generally, Numpy array with complex float values results in an array with elements with scientific notations. To avoid this we can use set_printoptions with suppress, and precision as parameters. This will help us to achieve our desired array with no scientific notation and with precision. Now let's get into code implementation.
Python3
import numpy as np
#defining the display funcrion
def GFG(arr,prec):
np.set_printoptions(suppress=True,precision=prec)
print(arr)
if __name__ == "__main__":
#defining the numpy array with float values
arr = np.array([123.456, 0.123456, 987.123])
#displaying the original array
print("Original Numpy Array : ")
print(arr,"\n")
#Converting the array to desired format and then displaying it
print("Numpy Array without without scientific notation : ")
GFG(arr,3)
Example:
Original Numpy Array :
[1.23456e+02 1.23456e-01 9.87123e+02]
Numpy Array without scientific notation:
[123.456 0.123 987.123]
Using Using set_printoptions() with .foramt()
We can use .foramt() with the set_printoptions() to achieve the desired numpy array. Lets now move to the code implementation.
Python3
import numpy as np
#defining the display funcrion
def GFG(arr):
np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
print(arr)
if __name__ == "__main__":
#defining the numpy array with float values
arr = np.array([123.456789, 0.400123456789, 987.123456789])
#displaying the original array
print("Original Numpy Array : ")
print(arr,"\n")
#Converting the array to desired format and then displaying it
print("Numpy Array without scientific notation : ")
GFG(arr)
Output
Original Numpy Array :
[1.23456789e+02 4.00123457e-01 9.87123457e+02]
Numpy Array without scientific notation :
[ 123.457 0.400 987.123]
Using array_str()
np.array_str() is a function in the Numpy library that is used to describe the array elements as strings. This method gives us the flexibility to set precision, suppress scientific notation, and format strings, thus helping us to generate the array without scientific notation and with the given precision. Let's hop into the code implementation.
Python3
import numpy as np
#defining the display funcrion
def GFG(arr,prec):
new = np.array_str(arr, precision=prec, suppress_small=True)
print(new)
if __name__ == "__main__":
#defining the numpy array with float values
arr = np.array([123.456789, 0.400123456789, 987.123456789])
#displaying the original array
print("Original Numpy Array : ")
print(arr,"\n")
#Converting the array to desired format and then displaying it
print("Numpy Array without scientific notation : ")
GFG(arr,3)
Output
Original Numpy Array :
[1.23456789e+02 4.00123457e-01 9.87123457e+02]
Numpy Array without scientific notation :
[123.457 0.4 987.123]
Similar Reads
How to prevent scientific notation in R? Scientific notations in R Programming Language are considered equivalent to the exponential formats. Scientific notations are used for numbers that are extremely large or small to be handled in the decimal form. In R Language, the E-notation is used for such numbers. In this article, we are going to
3 min read
Print full Numpy array without truncation The goal here is to print the full NumPy array without truncation, meaning all elements should be displayed regardless of the array's size. By default, NumPy truncates large arrays to avoid overwhelming the display. However, there are different methods to configure the printing options so that the e
2 min read
How to create an empty matrix with NumPy in Python? In Python, an empty matrix is a matrix that has no rows and no columns. NumPy, a powerful library for numerical computing, provides various methods to create matrices with specific properties, such as uninitialized values, zeros, NaNs, or ones. Below are different ways to create an empty or predefin
3 min read
numpy.array_str() in Python numpy.array_str()function is used to represent the data of an array as a string. The data in the array is returned as a single string. This function is similar to array_repr, the difference being that array_repr also returns information on the kind of array and its data type. Syntax : numpy.array_st
2 min read
How to create a constant matrix in Python with NumPy? A matrix represents a collection of numbers arranged in the order of rows and columns. It is necessary to enclose the elements of a matrix in parentheses or brackets. A constant matrix is a type of matrix whose elements are the same i.e. the element does not change irrespective of any index value th
4 min read