Wenn ich eine Reihe von Numpy Floats erstelle, bekomme ich eine Reihe von Python -SchwimmernPython

Python-Programme
Anonymous
 Wenn ich eine Reihe von Numpy Floats erstelle, bekomme ich eine Reihe von Python -Schwimmern

Post by Anonymous »

Der Code: < /p>

Code: Select all

import sys
import numpy as np

print(f"We are using Python {sys.version}", file=sys.stderr)
print(f"We are using numpy version {np.__version__}", file=sys.stderr)  # 2.2.1

def find_non_numpy_floats(x: any) -> bool:
if not (isinstance(x, np.float64)):
print(f"Found non-numpy.float64: {x} of type {type(x)}", file=sys.stderr)
return False
else:
return True

w: np.ndarray = np.zeros((2, 2), dtype=np.float64)

np.vectorize(lambda x: find_non_numpy_floats(x))(w)

assert (np.all(np.vectorize(lambda x: isinstance(x, np.float64))(w))), "try to keep using the numpy floats"
Ich erwarte numpy.zeros, dass sie ein Array von Numpy Float64 generieren, die nicht mit Python float sind, wenn ich richtig verstehe (IEEE 64- Bit Floats gegen etwas Python-Spezifisches?) < /p>
Die obigen entsteht jedoch: < /p>

Code: Select all

We are using Python 3.13.1 (main, Dec  9 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)]
We are using numpy version 2.2.1
Found non-numpy.float64: 0.0 of type 
Found non-numpy.float64: 0.0 of type 
Found non-numpy.float64: 0.0 of type 
Found non-numpy.float64: 0.0 of type 
und ein Behauptungsfehler.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post