The Wayback Machine - https://web.archive.org/web/20240906022012/https://www.geeksforgeeks.org/print-a-numpy-array-without-scientific-notation-in-python/
Open In App

Print a NumPy Array Without Scientific Notation in Python

Last Updated : 04 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

Display scientific notation as float in Python
In this article, the task is to display the scientific notation as float in Python. The scientific notation means any number expressed in the power of 10.for example- 340 can be written in scientific notation as 3.4 X102.in pythons, we use str.format() on a number with "{:e}" to format the number to scientific notation. str.format() formats the num
2 min read
How to suppress scientific notation when printing float values?
Scientific notation, also known as exponential notation, is a way of expressing numbers that are too large or too small to be conveniently written in decimal form. While useful in many scientific and engineering contexts, it can be cumbersome when you need to display float values in a more readable format without exponent notation. What is Scientif
2 min read
How to suppress the use of scientific notations for small numbers using NumPy?
Sometimes we have elements that are in scientific notations, and we have to suppress the scientific notation for simplicity. For this purpose, we call a function named as numpy.set_printoptions(). This function will help to suppress the scientific notation and display number to a certain precision. In this article we will see How to suppress the us
3 min read
Print full Numpy array without truncation
When printing a big NumPy array in the shell, the Python interpreter automatically shows only a small, truncated piece of the array, indicating that some values are missing in the textual representation of the array with the triple dots '...'. To overcome this we use some methods that we will discuss below: Print the full NumPy array without trunca
3 min read
NumPy Array Sorting | How to sort NumPy Array
Sorting an array is a very important step in data analysis as it helps in ordering data, and makes it easier to search and clean. In this tutorial, we will learn how to sort an array in NumPy. You can sort an array in NumPy: Using np.sort() functionin-line sortsorting along different axesUsing np.argsort() functionUsing np.lexsort() functionUsing s
4 min read
NumPy ndarray.tolist() Method | Convert NumPy Array to List
The ndarray.tolist() method converts a NumPy array into a nested Python list. It returns the array as an a.ndim-levels deep nested list of Python scalars. Data items are converted to the nearest compatible built-in Python type. Example C/C++ Code import numpy as np gfg = np.array([1, 2, 3, 4, 5]) print(gfg.tolist()) Output[1, 2, 3, 4, 5] SyntaxSynt
1 min read
NumPy ndarray.size() Method | Get Number of Elements in NumPy Array
The ndarray.size() method returns the number of elements in the NumPy array. It works the same as np.prod(a.shape), i.e., the product of the dimensions of the array. Example C/C++ Code import numpy as np arr = np.zeros((3, 4, 2), dtype = np.complex128) gfg = arr.size print (gfg) Output : 24Syntax Syntax: numpy.ndarray.size(arr) Parameters arr : [ar
1 min read
NumPy ndarray.__abs__() | Find Absolute Value of Elements in NumPy Array
The ndarray.__abs__() method returns the absolute value of every element in the NumPy array. It is automatically invoked when we use Python's built-in method abs() on a NumPy array. Example C/C++ Code import numpy as np gfg = np.array([1.45, 2.32, 3.98, 4.41, 5.55, 6.12]) print(gfg.__abs__()) Output[ 1 2 3 4 5 6] SyntaxSyntax: ndarray.__abs__() Ret
1 min read
NumPy ndarray.__ilshift__() | Shift NumPy Array Elements to Left
The ndarray.__ilshift__() method is an in-place left-shift operation. It shifts elements in the array to the left of the number of positions specified. Example C/C++ Code import numpy as np gfg = np.array([1, 2, 3, 4, 5]) # applying ndarray.__ilshift__() method print(gfg.__ilshift__(2)) Output[ 4 8 12 16 20] SyntaxSyntax: ndarray.__ilshift__($self,
1 min read
NumPy ndarray.__irshift__() | Shift NumPy Array Elements to Right
The ndarray.__irshift__() method returns a new array where each element is right-shifted by the value that is passed as a parameter. Example C/C++ Code import numpy as np gfg = np.array([1, 2, 3, 4, 5]) # applying ndarray.__irshift__() method print(gfg.__irshift__(2)) Output[0 0 0 1 1] SyntaxSyntax: ndarray.__irshift__($self, value, /) Parameter se
1 min read
NumPy ndarray.imag() Method | Get Imaginary Part in NumPy Array
The ndarray.imag() method returns the imaginary part of the complex number in the NumPy array. Note: Remember resulting data type for the imaginary value is 'float64'. Example C/C++ Code # import the important module in python import numpy as np # make an array with numpy gfg = np.array([1 + 2j, 2 + 3j]) # applying ndarray.imag() method geeks = np.
1 min read
NumPy ndarray.transpose() Method | Find Transpose of the NumPy Array
The ndarray.transpose() function returns a view of the array with axes transposed. For a 1-D array, this has no effect, as a transposed vector is simply the same vector.For a 2-D array, this is a standard matrix transpose.For an n-D array, if axes are given, their order indicates how the axes are permuted. If axes are not provided and arr.shape = (
2 min read
Scientific GUI Calculator using Tkinter in Python
Prerequisite: Python GUI – tkinter In this article, we are going to create GUI Scientific Calculator using Python. As you can see, calculating large numbers nowadays is difficult or time-consuming. We've created a simple Scientific Calculator GUI using Python that allows you to perform simple and complex calculations. To implement GUI we will use t
13 min read
Python | Numpy numpy.resize()
With the help of Numpy numpy.resize(), we can resize the size of an array. Array can be of any shape but to resize it we just need the size i.e (2, 2), (2, 3) and many more. During resizing numpy append zeros if values at a particular place is missing. Parameters: new_shape : [tuple of ints, or n ints] Shape of resized array refcheck : [bool, optio
2 min read
Python | Numpy numpy.transpose()
With the help of Numpy numpy.transpose(), We can perform the simple function of transpose within one line by using numpy.transpose() method of Numpy. It can transpose the 2-D arrays on the other hand it has no effect on 1-D arrays. This method transpose the 2-D numpy array. Parameters: axes : [None, tuple of ints, or n ints] If anyone wants to pass
2 min read
Python | Numpy numpy.ndarray.__lt__()
With the help of numpy.ndarray.__lt__() method of Numpy, We can find that which element in an array is less than the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__lt__($self, value, /) Return: self<value Example #1 : In this example we can see that
1 min read
Python | Numpy numpy.ndarray.__gt__()
With the help of numpy.ndarray.__gt__() method of Numpy, We can find that which element in an array is greater then the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__gt__($self, value, /) Return: self>value Example #1 : In this example we can see th
1 min read
Python | Numpy numpy.ndarray.__le__()
With the help of numpy.ndarray.__le__() method of Numpy, We can find that which element in an array is less than or equal to the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__le__($self, value, /) Return: self<=value Example #1 : In this example we
1 min read
Python | Numpy numpy.ndarray.__ge__()
With the help of numpy.ndarray.__ge__() method of Numpy, We can find that which element in an array is greater then or equal to the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__ge__($self, value, /) Return: self>=value Example #1 : In this example
1 min read
Python | Numpy numpy.ndarray.__ne__()
With the help of numpy.ndarray.__ne__() method of Numpy, We can find that which element in an array is not equal to the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__ne__($self, value, /) Return: self!=value Example #1 : In this example we can see that
1 min read
Python | Numpy numpy.ndarray.__neg__()
With the help of numpy.ndarray.__neg__() method of Numpy, one can multiply each and every element of an array with -1. Hence, the resultant array having values like positive values becomes negative and negative values become positive. Syntax: ndarray.__neg__($self, /) Return: -self Example #1 : In this example we can see that after applying numpy._
1 min read
Python | Numpy numpy.ndarray.__pos__()
With the help of numpy.ndarray.__pos__() method of Numpy, one can multiply each and every element of an array with 1. Hence, the resultant array having values same as original array. Syntax: ndarray.__pos__($self, /) Return: +self Example #1 : In this example we can see that after applying numpy.__pos__(), we get the simple array that can be the sa
1 min read
Python | Numpy numpy.ndarray.__truediv__()
With the help of Numpy numpy.ndarray.__truediv__(), we can divide a particular value that is provided as a parameter in the ndarray.__truediv__() method. Value will be divided to each and every element in a numpy array. Syntax: ndarray.__truediv__($self, value, /) Return: self/value Example #1 : In this example, we can see that each element in an a
1 min read
Python | Numpy numpy.ndarray.__sub__()
With the help of Numpy numpy.ndarray.__sub__(), We can subtract a particular value that is provided as a parameter in the ndarray.__sub__() method. Value will be subtracted to each and every element in a numpy array. Syntax: ndarray.__sub__($self, value, /) Return: self-value Example #1 : In this example we can see that each and every element in an
1 min read
Python | Numpy numpy.ndarray.__add__()
With the help of Numpy numpy.ndarray.__add__(), we can add a particular value that is provided as a parameter in the ndarray.__add__() method. Value will be added to each and every element in a numpy array. Syntax: ndarray.__add__($self, value, /) Return: self+value Example #1 : In this example we can see that each and every element in an array is
1 min read
Python | Numpy numpy.ndarray.__floordiv__()
With the help of Numpy numpy.ndarray.__floordiv__(), one can divide a particular value that is provided as a parameter in the ndarray.__floordiv__() method. Value will be divided to each and every element in a numpy array and remember it always gives the floor value after division. Syntax: ndarray.__floordiv__($self, value, /) Return: self//value E
1 min read
Python | Numpy numpy.ndarray.__mod__()
With the help of Numpy numpy.ndarray.__mod__(), every element in an array is operated on binary operator i.e mod(%). Remember we can use any type of values in an array and value for mod is applied as the parameter in ndarray.__mod__(). Syntax: ndarray.__mod__($self, value, /) Return: self%value Example #1 : In this example we can see that value tha
1 min read
Python | Numpy numpy.ndarray.__invert__()
With the help of Numpy numpy.ndarray.__invert__(), one can invert the elements of an array. We don't have to provide any type of parameter but remember that this method only works for integer values. Syntax: ndarray.__invert__($self, /) Return: ~self Example #1 : In this example we can see that every element in an array is operated on a unary opera
1 min read
Python | Numpy numpy.ndarray.__divmod__()
With the help of Numpy numpy.ndarray.__divmod__() method, we will get two arrays one is having elements that is divided by value that is provided in numpy.ndarray.__divmod__() method and second is having elements that perform mod operation with same value as provided in numpy.ndarray.__divmod__() method. Syntax: ndarray.__divmod__($self, value, /)
1 min read
Python | Numpy numpy.ndarray.__pow__()
With the help of Numpy numpy.ndarray.__pow__() method, we will get all the elements powered with the value that is provided as a parameter in numpy.ndarray.__pow__() method. Syntax: ndarray.__pow__($self, value, mod=None, /) Return: pow(self, value, mod) Example #1 : In this example we can see that every element get powered with the value that is p
1 min read