对uncertainty.ufloat对象运行np.arctan2会导致错误。“属性错误:“Variable”对象没有属性“arctan2”
Someone else asked this question before,然而,这是因为与sympy的名称冲突。删除名称冲突修复了问题。
相反,我得到的错误没有导入任何其他东西。下面是最小的代码,如果我用它制作一个新的jupyter notebook,它会给我带来错误:
from uncertainties import ufloat
import numpy as np
ccos = ufloat(-3.45694E-05, 1.43107E-06)
csin = ufloat(-0.000363727, 1.36989E-06)
np.arctan2(csin,ccos)
字符串
抛出错误
AttributeError Traceback (most recent call last)
Untitled-1.ipynb Cell 1 in ()
4 ccos = ufloat(-3.45694E-05, 1.43107E-06)
5 csin = ufloat(-0.000363727, 1.36989E-06)
----> 7 np.arctan2(csin,ccos)
AttributeError: 'Variable' object has no attribute 'arctan2'
型
为什么会这样?
2条答案
按热度按时间cu6pst1q1#
这很可能是因为
ufloat
不是原生的numpy
数据类型。您可以使用
uncertainties
提供的math
函数。我刚刚检查了以下修改后的代码,它工作正常:
字符串
其输出:
型
7y4bm7vi2#
看起来numpy不支持不确定性包。
要解决这个问题,可以使用数学函数的不确定性包版本:
字符串
(this可能是太简单了,不确定我是否应该删除这个问题)