天天看点

Python的Numpy.log报错TypeError: loop of ufunc does not support argument 0 of type float...

版权声明:转载请注明作者(独孤尚良dugushangliang)出处:https://blog.csdn.net/dugushangliang/article/details/119446978

之前使用np.log()好好的,结果今天直接运行代码,突然报错了,报错如下:

TypeError: loop of ufunc does not support argument 0 of type float which has no callable log method

一番探索不再详述,直奔主题。

报错的地方在这行代码:

za=np.log((zm-zd)/z0)
           
Python的Numpy.log报错TypeError: loop of ufunc does not support argument 0 of type float...
Python的Numpy.log报错TypeError: loop of ufunc does not support argument 0 of type float...

症结就在zd的格式是object。np.log()传入的不能是字符串。

可为什么下图所示可以计算a呢?因为zd在计算时直接被智能识别为float了。但此时a的格式还是object而不是float。

Python的Numpy.log报错TypeError: loop of ufunc does not support argument 0 of type float...

 所以,转到float格式即可。

zd=zd.astype('float')
           

独孤尚良dugushangliang——著