小编Ohm*_*Ohm的帖子

SciPy插值ValueError:x和y数组在插值轴上的长度必须相等

我正在尝试使用SciPy.interpolate的interp1d。我“插入”了两个大小相同的数组(filtered_mass和Integrated_column),但是仍然给我ValueError,数组的大小必须相等。怎么会这样?

这是我在此部分中使用的代码:

def interp_integrated_column(self, definition):
    '''  (string) -> interpolated_function(mass)
    This functions output the interpolated value of the integrated columns
    as function of the mass of the WIMP (mDM)
    '''
    print self.filtered_mass_array
    print "len(filtered_mass)", len(self.filtered_mass_array) , "len(integrated_column)", len(self.integrated_columns_values[definition])
    print self.integrated_columns_values[definition]
    interpolated_values = interp1d(self.filtered_mass_array, self.integrated_columns_values[definition])
    return interpolated_values
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

[5.0, 6.0, 8.0, 10.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 330.0, 360.0, 400.0, 450.0, 500.0, 550.0, …
Run Code Online (Sandbox Code Playgroud)

python arrays interpolation numpy scipy

2
推荐指数
1
解决办法
8866
查看次数

宇宙学宇宙学问题,宇宙学.H(z)函数是无单位的

我正在尝试使用astropy.cosmology.正如文档所说,当我使用Hubble参数方法时,它应该给我一个单位的值 - astropy.cosmology documentation

但它给了我一个数字,可以在这里看到 -

ohm@ohm-ThinkCentre-M57:~/projects/mucalc$ python
Python 2.7.3 (default, Sep 26 2013, 20:08:41) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from astropy import cosmology
>>> cosmology.core.set_current(cosmology.Planck13)
>>> H0 = cosmology.H(10**6)
>>> print H0
647883886243.0
>>> H0.value
ERROR: AttributeError: 'numpy.float64' object has no attribute 'value' [unknown]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'numpy.float64' object has no attribute 'value'
>>> 
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?

python astropy

2
推荐指数
1
解决办法
256
查看次数

如何用十进制标记后的固定号写入astropy Table对象值?

如何保留将值写入astropy Table对象的格式,以及将表写入文件时?

我正在对从具有以下形式的值的txt文件中获取的数据执行计算:

3.160792680383711552e-04    9.180738349762776473e-02    7.997959651731425081e-05    9.978300086189421103e-01
Run Code Online (Sandbox Code Playgroud)

然后我读取这些值,根据每行的值添加另一列作为我的计算,并且我想将它们写回文件,因此我写的文件将与旧文件的列相同,而另一列这是我计算的值.但是当我尝试这样做时,它会改变写入这些值的格式:

0.000316079268038   0.0918073834976   7.99795965173e-05   0.997830008619 
Run Code Online (Sandbox Code Playgroud)

python python-2.7 astropy

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

有效地使用函数作为参数

我想在Julia语言中实现一个通用的Runge-Kutta步骤函数.在Python中,我可以将一个函数作为此RK4函数作为输入获取的参数之一传递.如果我像朱莉娅那样做,会有性能损失吗?

我的功能看起来像这样:

function uv_rk4_step(rhs,Vs,Ps)
  Vs_k1 = rhs(Vs,Ps)
  Vs_k1 = Ps.dt*Vs_k1
  Vs_k2 = rhs((Vs+(1/2)*Vs_k1),Ps)
  Vs_k2 = Ps.dt*Vs_k2
  Vs_k3 = rhs((Vs+(1/2)*Vs_k2),Ps)
  Vs_k3 = Ps.dt*Vs_k3
  Vs_k4 = rhs((Vs+(1/2)*Vs_k3),Ps)
  Vs_k4 = Ps.dt*Vs_k4
  Vs_next = Vs+(1/6)*Vs_k1+(1/3)*Vs_k2+(1/3)*Vs_k3+(1/6)*Vs_k4
end
Run Code Online (Sandbox Code Playgroud)

其中Ps是具有模型参数的Julia类型,Vs是ODE变量的多维数组,rhs是ODE的右侧(部分时间导数).

function runge-kutta julia

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

Python:加速我的 Runge-Kutta 集成代码挑战

我正在使用随附的代码来集成Fitzhugh-Nagumo模型的一个版本:

from scipy.integrate import odeint
import numpy as np
import time

P = {'epsilon':0.1,
     'a1':1.0,
     'a2':1.0,
     'b':2.0,
     'c':0.2}

def fhn_rhs(V,t,P):
    u,v = V[0],V[1]
    u_t = u - u**3 - v
    v_t = P['epsilon']*(u - P['b']*v - P['c'])
    return np.stack((u_t,v_t))

def integrate(func,V0,t,args,step='RK4'):
    start = time.clock()
    P = args[0]
    result=[V0]
    for i,tmp in enumerate(t[1:]):
        result.append(RK4step(func,result[i],tmp,P,(t[i+1]-t[i])))
    print "Integration took ",time.clock() - start, " s"
    return np.array(result)


def RK4step(rhs,V,t,P,dt):
    k_1 = dt*rhs(V,t,P)
    k_2 = dt*rhs((V+(1.0/2.0)*k_1),t,P)
    k_3 = dt*rhs((V+(1.0/2.0)*k_2),t,P)
    k_4 = dt*rhs((V+k_3),t,P)
    return …
Run Code Online (Sandbox Code Playgroud)

python numpy python-2.7 runge-kutta numba

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

遍历astropy.table表对象的行

从astropy.table遍历Table对象的行的最聪明方法是什么?

是这样的吗?

for row in table:
    ....
Run Code Online (Sandbox Code Playgroud)

python astropy

0
推荐指数
1
解决办法
1270
查看次数

如何将序列乘以“float”类型的非整数?

我正在尝试将一组数组乘以某个数字。也就是说,将每个数组的每个值乘以相同的常数。我试图这样做:

>>> a = [[1,1],[1,1]]
>>> b = [[1,1],[1,1]]
>>> c = [[1,1],[1,1]]
>>> 0.1 * [a,b,c]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
Run Code Online (Sandbox Code Playgroud)

有没有更聪明的“Numpier”方式来做到这一点而不是创建一个 for 循环?

python arrays numpy

-2
推荐指数
1
解决办法
4845
查看次数