在StackOverflow上找到了一个类似的问题:

https://stackoverflow.com/questions/36609196/attributeerror-float-object-has-no-attribute-sqrt

 

numpy doesn't know how to handle sympy's Float type.

(Pdb) type(Wapproxlist[0])
<class 'sympy.core.numbers.Float'>

Convert it to a numpy array before calling np.mean and np.std.

Wapproxlist = np.array(Wapproxlist, dtype=np.float64) # can use np.float32 as well

print('mean=%.3f stdv=%.3f' % (np.mean(Wapproxlist), np.std(Wapproxlist)))
print('mean=%.3f stdv=%.3f' % (np.mean(Wlist), np.std(Wlist)))

output:

mean=4.177 stdv=10.283
mean=4.180 stdv=10.300

Note: If you're looking to speed this up, you'll want to avoid sympy. Symbolic solvers are pretty cool, but they're also very slow compared to floating point computations.

原因:

numpy处理不了sympy中的Float数据类型,要解决这类问题,要把出错的数据转换为np.float32,或者np.flaot64 就行了。

 

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐