Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8564435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:12:01+00:00 2026-06-11T17:12:01+00:00

Simple rounding of a floating point numpy array seems not working for some reason..

  • 0

Simple rounding of a floating point numpy array seems not working for some reason..

I get numpy array from reading a huge img (shape of (7352, 7472)). Ex values:

>>> imarray[3500:3503, 5000:5003]
array([[ 73.33999634,  73.40000153,  73.45999908],
       [ 73.30999756,  73.37999725,  73.43000031],
       [ 73.30000305,  73.36000061,  73.41000366]], dtype=float32)

And for rounding I’ve been just trying to use numpy.around() for the raw value, also writing values to a new array, a copie of raw array, but for some reason no results..

arr=imarray
numpy.around(imarray, decimals=3, out=arr)
arr[3500,5000] #results in 73.3399963379, as well as accessing imarray

So, even higher precision!!!
Is that because of such big array?

I need to round it to get the most frequent value (mode), and I’m searching the vay to avoid more and more libraries..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:12:02+00:00Added an answer on June 11, 2026 at 5:12 pm

    Your array has dtype float32. That is a 4-byte float.
    The closest float to 73.340 representable using float32 is roughly 73.33999634:

    In [62]: x = np.array([73.33999634, 73.340], dtype = np.float32)
    
    In [63]: x
    Out[63]: array([ 73.33999634,  73.33999634], dtype=float32)
    

    So I think np.around is rounding correctly, it is just that your dtype has too large a granularity to round to the number you might be expecting.

    In [60]: y = np.around(x, decimals = 3)
    
    In [61]: y
    Out[61]: array([ 73.33999634,  73.33999634], dtype=float32)
    

    Whereas, if the dtype were np.float64:

    In [64]: x = np.array([73.33999634, 73.340], dtype = np.float64)
    
    In [65]: y = np.around(x, decimals = 3)
    
    In [66]: y
    Out[66]: array([ 73.34,  73.34])
    

    Note that even though printed representation for y shows 73.34, it is not necessarily true that the real number 73.34 is exactly representable as a float64 either. The float64 representation is probably just so close to 73.34 that NumPy chooses to print it as 73.34.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is a simple example of floating point/rounding error? When I execute
Possible Duplicate: Is JavaScript's Math broken? Strange result with floating point addition Some simple
I've posted a sample here - http://jsfiddle.net/bizl/tSVHu/ This simple array's long values get changed
I ran into something that seems odd. SQL Server appears to be rounding some
Imagine you have a large array of floating point numbers, of all kinds of
Simple thing I'm doing is connecting to retrieving user's name from Facebook and passing
Simple enough situation. I've got a MongoDB database with a bunch of information from
http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/ I have been about this lately to review C++. In general computing class
Need a simple a way of rounding off an Image. I need the corners
I'm doing what seems like simple math in an android app, however I keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.