Es wird versucht, ein Problem mit der veralteten NumPy-Asskala zu beheben
Posted: 03 Jan 2025, 17:36
Beim Versuch, ein altes Python-Skript zu aktualisieren, ist der folgende Fehler aufgetreten:
Im Einzelnen:
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:
habe aber diesen Fehler erhalten:
Wie kann ich das lösen?
Code: Select all
module 'numpy' has no attribute 'asscalar'. Did you mean: 'isscalar'?
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 Folgendes versucht:
Code: Select all
offsets = map.item(offsets)
scale = map.item( scale)
Code: Select all
AttributeError: type object 'map' has no attribute 'item'