Page 1 of 1

Es wird versucht, ein Problem mit der veralteten NumPy-Asskala zu beheben

Posted: 03 Jan 2025, 17:36
by Guest
Beim Versuch, ein altes Python-Skript zu aktualisieren, ist der folgende Fehler aufgetreten:

Code: Select all

module 'numpy' has no attribute 'asscalar'. Did you mean: 'isscalar'?
Im Einzelnen:

Code: Select all

def calibrate(x, y, z):
# H = numpy.array([x, y, z, -y**2, -z**2, numpy.ones([len(x), 1])])
H = numpy.array([x, y, z, -y**2, -z**2, numpy.ones([len(x)])])
H = numpy.transpose(H)
w = x**2

(X, residues, rank, shape) = linalg.lstsq(H, w)

OSx = X[0] / 2
OSy = X[1] / (2 * X[3])
OSz = X[2] / (2 * X[4])

A = X[5] + OSx**2 + X[3] * OSy**2 + X[4] * OSz**2
B = A / X[3]
C = A / X[4]

SCx = numpy.sqrt(A)
SCy = numpy.sqrt(B)
SCz = numpy.sqrt(C)

# type conversion from numpy.float64 to standard python floats
offsets = [OSx, OSy, OSz]
scale = [SCx, SCy, SCz]

offsets = map(numpy.asscalar, offsets)
scale = map(numpy.asscalar, scale)

return (offsets, scale)
Ich habe festgestellt, dass asscalar seit NumPy 1.16 veraltet ist. Ich habe eine Referenz gefunden, in der es hieß, numpy.ndarray.item zu verwenden, aber ich habe keine Ahnung, wie das geht.
Ich habe Folgendes versucht:

Code: Select all

offsets = map.item(offsets)
scale = map.item( scale)
habe aber diesen Fehler erhalten:

Code: Select all

AttributeError: type object 'map' has no attribute 'item'
Wie kann ich das lösen?