Skip to content

BUG: tolist() fails to respect decimal rounding, unexpectedly outputs excess floating-point digits!!! #29400

@zhuyyx

Description

@zhuyyx

Describe the issue:

即使四舍五入了, .tolist()依然在输出多余的小数位!!!!

Reproduce the code example:

import numpy as np
np.set_printoptions(precision=2, suppress=True)

states = np.around(states, decimals=2).astype(np.float32)   
print(f"states:{states}\n\n")
states: [[-0.06  0.37  0.05 -2.33 -0.04  2.7  -1.08  0.04]]

print(f"states:{states.tolist()}\n\n")
states:[[-0.05999999865889549, 0.3700000047683716, 0.05000000074505806, -2.3299999237060547, -0.03999999910593033, 2.700000047683716, -1.0800000429153442, 0.03999999910593033]]

Error message:

Python and NumPy Versions:

python --version

Python 3.10.18

pip list | grep numpy
numpy 1.26.4

Runtime Environment:

cat /etc/issue

Ubuntu 22.04.3 LTS \n \l

uname -a
Linux unitree-eai 5.15.0-88-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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