Python Forum
Get numpy ceil and floor value for nearest two decimals
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get numpy ceil and floor value for nearest two decimals
#5
As I suggested:
import numpy as np
a = np.array([-1.784, -1.5888, -0.24444, 0.25555, 1.5, 1.75, 2.0])
a_rounded = np.around(a, decimals=2)
print(f"{a_rounded}")
Output:
[-1.78 -1.59 -0.24 0.26 1.5 1.75 2. ]
Actually I'm just wondering if that's your need or if you're asking as well for "zeros" to complete decimals; for instance "1.5" and "2." must provide "1.50" and "2.00" respectively
Reply


Messages In This Thread
RE: Get numpy ceil and floor value for nearest two decimals - by paul18fr - Jun-07-2023, 07:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing a cycle to find the nearest point from the array Tysrusko 0 223 May-10-2024, 11:49 AM
Last Post: Tysrusko
  Python won 't do decimals SomebodySmart 5 861 Jun-08-2023, 07:14 PM
Last Post: buran
  compare and find the nearest element ? mr_gentle_sausage 4 1,161 Jan-15-2023, 07:11 AM
Last Post: DPaul
  Floor approximation problem in algorithm gradlon93 3 1,036 Dec-14-2022, 07:48 PM
Last Post: Gribouillis
  Adding Decimals to classes with OOP + rounding to significant digits (ATM demo) Drone4four 7 2,447 May-04-2022, 06:15 AM
Last Post: Drone4four
  Floor division problem with plotting x-axis tick labels Mark17 5 2,240 Apr-03-2022, 01:48 PM
Last Post: Mark17
  floats 2 decimals rwahdan 3 1,711 Dec-19-2021, 10:30 PM
Last Post: snippsat
  Converting decimals stylingpat 3 2,218 Mar-27-2021, 02:32 PM
Last Post: deanhystad
Photo Locate Noise floor level for a spectral data in Python Ranjan_Pal 1 3,140 Dec-19-2020, 10:04 AM
Last Post: Larz60+
  Floor division return value Chirumer 8 3,990 Nov-26-2020, 02:34 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020