Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
numpy.angle() in Python
Next article icon

numpy.around() in Python

Last Updated : 08 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

numpy.around(arr, decimals = 0, out = None) : This mathematical function helps user to evenly round array elements to the given number of decimals.

Parameters :

array : [array_like] Input array.
decimal : [int, optional] Decimal places we want to round off.

Default = 0. In case of -ve decimal, it specifies the n0. of positions to the left of the decimal point.

out : [optional] Output resulted array

Return :

  An array with all array elements being rounded off,  having same type as input 

 
Code #1 : Working




# Python program explaining
# around() function
  
import numpy as np
  
in_array = [.5, 1.5, 2.5, 3.5, 4.5, 10.1]
print ("Input array : \n", in_array)
  
round_off_values = np.around(in_array)
print ("\nRounded values : \n", round_off_values)
  
  
in_array = [.53, 1.54, .71]
print ("\nInput array : \n", in_array)
  
round_off_values = np.around(in_array)
print ("\nRounded values : \n", round_off_values)
  
in_array = [.5538, 1.33354, .71445]
print ("\nInput array : \n", in_array)
  
round_off_values = np.around(in_array, decimals = 3)
print ("\nRounded values : \n", round_off_values)
 
 

Output :

  Input array :    [0.5, 1.5, 2.5, 3.5, 4.5, 10.1]    Rounded values :    [  0.   2.   2.   4.   4.  10.]    Input array :    [0.53, 1.54, 0.71]    Rounded values :    [ 1.  2.  1.]    Input array :    [0.5538, 1.33354, 0.71445]    Rounded values :    [ 0.554  1.334  0.714]

 
Code 2 : Working




# Python program explaining
# around() function
  
import numpy as np
  
in_array = [1 ,4, 7, 9, 12]
print ("Input array : \n", in_array)
  
round_off_values = np.around(in_array)
print ("\nRounded values : \n", round_off_values)
  
  
in_array = [133 ,344, 437, 449, 12]
print ("\nInput array : \n", in_array)
  
round_off_values = np.around(in_array, decimals = -2)
print ("\nRounded values upto 2: \n", round_off_values)
  
in_array = [133 ,344, 437, 449, 12]
print ("\nInput array : \n", in_array)
  
round_off_values = np.around(in_array, decimals = -3)
print ("\nRounded values upto 3: \n", round_off_values)
 
 

Output :

  Input array :    [1, 4, 7, 9, 12]    Rounded values :    [ 1  4  7  9 12]    Input array :    [133, 344, 437, 449, 12]    Rounded values upto 2:    [100 300 400 400   0]    Input array :    [133, 344, 437, 449, 12]    Rounded values upto 3:    [0 0 0 0 0]  

 



Next Article
numpy.angle() in Python
author
mohit gupta_omg :)
Improve
Article Tags :
  • Python
  • Python numpy-Mathematical Function
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • numpy.arange() in Python
    numpy.arange() function creates an array of evenly spaced values within a given interval. It is similar to Python's built-in range() function but returns a NumPy array instead of a list. Let's understand with a simple example: [GFGTABS] Python import numpy as np #create an array arr= np.arange(5 , 1
    2 min read
  • NumPy Array in Python
    NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C
    2 min read
  • numpy.angle() in Python
    numpy.angle() function is used when we want to compute the angle of the complex argument. A complex number is represented by “ x + yi " where x and y are real number and i= (-1)^1/2. The angle is calculated by the formula tan-1(x/y). Syntax : numpy.angle(z, deg=0) Parameters : z : [array_like] A com
    2 min read
  • numpy.fabs() in Python
    numpy.fabs() function is used to compute the absolute values element-wise. This function returns the absolute values (positive magnitude) of the data in arr. It always return absolute values in floats. Syntax : numpy.fabs(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, u
    2 min read
  • numpy.greater() in Python
    The numpy.greater() checks whether x1 is greater than x2 or not. Syntax : numpy.greater(x1, x2[, out]) Parameters : x1, x2 : [array_like]Input arrays. If x1.shape != x2.shape, they must be broadcastable to a common shape out : [ndarray, boolean]Array of bools, or a single bool if x1 and x2 are scala
    2 min read
  • numpy.floor() in Python
    The numpy.floor() function returns the largest integer less than or equal to each element in the input array. It effectively rounds numbers down to the nearest whole number. Let's understand with an example: [GFGTABS] Python import numpy as np a = [0.5, 1.5, 2.5, 3, 4.5, 10.1] res = np.floor(a) prin
    1 min read
  • numpy.inner() in python
    numpy.inner(arr1, arr2): Computes the inner product of two arrays. Parameters : arr1, arr2 : array to be evaluated. Return: Inner product of the two arrays. Code #1 : # Python Program illustrating # numpy.inner() method import numpy as geek # Scalars product = geek.inner(5, 4) print("inner Prod
    1 min read
  • numpy.fix() in Python
    The numpy.fix() is a mathematical function that rounds elements of the array to the nearest integer towards zero. The rounded values are returned as floats. Syntax : numpy.fix(a, b = None) Parameters : a : [array_like] Input array to be floated. b : [ndarray, optional] Output array. Return : The arr
    2 min read
  • numpy.argwhere() in Python
    numpy.argwhere() function is used to find the indices of array elements that are non-zero, grouped by element. Syntax : numpy.argwhere(arr) Parameters : arr : [array_like] Input array. Return : [ndarray] Indices of elements that are non-zero. Indices are grouped by element. Code #1 : # Python progra
    1 min read
  • numpy.allclose() in Python
    numpy.allclose() function is used to find if two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(arr2)) and the absolute difference atol are added together to compare against the absolute differenc
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences