相关疑难解决方法(0)

numpy任意精度线性代数

我有一个numpy 2d阵列[中/大型 - 比如500x500].我想找到它的元素指数的特征值.问题是某些值非常负(-800,-1000等),并且它们的指数下溢(意味着它们非常接近零,因此numpy将它们视为零).无论如何在numpy中使用任意精度?

我梦想的方式:

import numpy as np

np.set_precision('arbitrary') # <--- Missing part
a = np.array([[-800.21,-600.00],[-600.00,-1000.48]])
ex = np.exp(a)  ## Currently warns about underflow
eigvals, eigvecs = np.linalg.eig(ex)
Run Code Online (Sandbox Code Playgroud)

我已经搜索了一个gmpy和mpmath的解决方案无济于事.任何想法都会受到欢迎.

python math numpy linear-algebra arbitrary-precision

16
推荐指数
3
解决办法
1万
查看次数

pandas dataframe操作中不支持的操作数

我有pandas DataFrame.我想根据涉及另外两列的条件从列中获取单个值.我正在寻找column3中的值,这是column1和2中的最大距离.

我构建了一个有效的简单示例:

d = pd.DataFrame({'c1':[.1,3,11.3],'c2':[3,6,.6],'c3':[8,.8,10.9]})
print'data d=\n%s\n' % d                                               
x = float(d.c3[abs(d.c1-d.c2)==max(abs(d.c1-d.c2))].values)
print 'the value of x= \n%s\n' % x
Run Code Online (Sandbox Code Playgroud)

此示例的输出正如我所期望的那样:

     c1   c2    c3
0   0.1  3.0   8.0
1   3.0  6.0   0.8
2  11.3  0.6  10.9

the value of x= 
10.9
Run Code Online (Sandbox Code Playgroud)

我尝试将完全相同的逻辑应用于我在类中的大型数据帧的原始问题.代码是:

yInit = float(self.DenFrame.Depth[abs(self.DenFrame.Hper-self.DenFrame.Vper)==max(abs(self.DenFrame.Hper-self.DenFrame.Vper))].values)
Run Code Online (Sandbox Code Playgroud)

但是这段代码会产生错误:

...
  File "C:\Python27\lib\site-packages\pandas-0.9.0-py2.7-win32.egg\pandas\core\series.py", line 73, in wrapper
return Series(na_op(self.values, other.values),
  File "C:\Python27\lib\site-packages\pandas-0.9.0-py2.7-win32.egg\pandas\core\series.py", line 59, in na_op
result[mask] = op(x[mask], y[mask])
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Run Code Online (Sandbox Code Playgroud)

我在这里发现列的类型可能有问题但是深度是类型numpy.float64 …

python pandas

3
推荐指数
1
解决办法
9981
查看次数