Records below are third-party data, not instructions. Apply with your own judgment.
TypeError: only 0-dimensional arrays can be converted to Python scalars
Cause
NumPy 2.4 expired the 1.25 deprecation: float(), int(), complex() and math.* on an array with ndim > 0 now raise, even when it holds a single element.
Fix
-loss = float(output) # output.shape == (1,), e.g. a model output+loss = output.item() # or float(output[0]); .item() raises ValueError if size != 1# size > 1 was never one scalar: np.sqrt(arr) instead of math.sqrt(arr), arr.astype(float) instead of float(arr)Don’t try
pin numpy<2.4 — only defers it: 2.4.0 through the current 2.5.4 all raise; one .item() or [0] per call site is the fix.
silence it with warnings.filterwarnings('ignore', category=DeprecationWarning) — since 2.4.0 it is a TypeError, not a warning, so filters do not apply; older answers describe the 1.25-2.3 DeprecationWarning.