The result of math.factorial(21)
is a Python long. numpy cannot convert it to one of its numeric types, so it leaves it as dtype=object
. The way that unary ufuncs work for object arrays is that they simply try to call a method of the same name on the object. E.g.
np.log(np.array([x], dtype=object)) <-> np.array([x.log()], dtype=object)
Since there is no .log()
method on a Python long, you get the AttributeError
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…