Skip to content

MAINT: Improve float16 and float32 printing #28703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add release note
  • Loading branch information
f2013519 committed Apr 15, 2025
commit f0a33ae9d034838f9b89a838e456b3713b1f58ce
2 changes: 2 additions & 0 deletions doc/release/upcoming_changes/28703.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Printing of ``np.float16`` and ``np.float32`` scalars and arrays have been improved by
adjusting the transition to scientific notation based on the floating point precision.
6 changes: 2 additions & 4 deletions numpy/_core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,13 +990,11 @@ def fillFormat(self, data):

# choose exponential mode based on the non-zero finite values:
abs_non_zero = absolute(finite_vals[finite_vals != 0])

# consider data type while deciding the max cutoff for exp format
exp_cutoff_max = 10.**min(8, np.finfo(data.dtype).precision)

if len(abs_non_zero) != 0:
max_val = np.max(abs_non_zero)
min_val = np.min(abs_non_zero)
# consider data type while deciding the max cutoff for exp format
exp_cutoff_max = 10.**min(8, np.finfo(data.dtype).precision)
with errstate(over='ignore'): # division can overflow
if max_val >= exp_cutoff_max or (not self.suppress_small and
(min_val < 0.0001 or max_val / min_val > 1000.)):
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy