如何在python中调用特定的INT

如何在python中调用特定的INT,python,arrays,int,Python,Arrays,Int,要计算h,我们必须有f1、f2和fn的n*n矩阵。 f可以有各种可能的功能,从ODE到简单的方程式。为了简化,我选择了xx+yy。 如何调用特定的int,这里是f,例如f[2],它会自动将2放入xx[i]+yy[i]f[2]=0.14+33.8 一般来说,如何调用特定的int,如我上面提到的f xx=np.array([0.1,0.12,0.14,0.16]) yy=np.array([32,33,33.8,34.1]) C=[[13,18],[28,-27]] #f[i]=xx[i]+yy

要计算
h
,我们必须有
f1
f2
fn
n*n
矩阵。
f
可以有各种可能的功能,从ODE到简单的方程式。为了简化,我选择了
xx+yy
。 如何调用特定的
int
,这里是
f
,例如
f[2]
,它会自动将
2
放入
xx[i]+yy[i]
<代码>f[2]=0.14+33.8 一般来说,如何调用特定的int,如我上面提到的
f

xx=np.array([0.1,0.12,0.14,0.16])
yy=np.array([32,33,33.8,34.1])
C=[[13,18],[28,-27]]


#f[i]=xx[i]+yy[i]


r1=[[f1,f2]]
r2=[[f1],[f2]]

m=np.dot(r1,C)
z=np.dot(m,r2)
h=np.linalg.det(z)
print('matrix=',h)
它可以是:

A=xx[i]*squad(xx[i]/8)
B=odeint(def,0,A) #which is an ode
F[i]=B-yy[i]

只要创建一个函数来构造f,将底层函数作为参数,
const
函数将函数
func
应用于
xx
yy
中的每一对元素,因此任何接受浮点元组的函数都应该工作

def const(func):
    return list(map(func, zip(xx, yy)))

f = const(sum)
# f[2] = 33.939999999999998

ur代码中的主要内容是
def new_计算(n):

从数学导入* 将numpy作为np导入 从scipy.integrate导入四元组 从scipy.integrate导入odeint min=l=m=n=k=t=dec=chi=chiB=chiCMB=hh=cpl=None

xx=np.array([0.01,0.012,0.014,0.016])
yy=np.array([32.95388698,33.87900347,33.84214074,34.11856704])
z = [0.01, 0.012]  # new list

Cov=[[137,168],[28155,-2217]]


def ant(z,O_m,O_D):           
    return 1/sqrt(((1+z)**2)*(1+O_m*z)-z*(2+z)*O_D)

def HDE(y,z):
    a=1/(1+z)        
    dydz = -y*((((H0*(3*b-3+g)*O_m*(a**(3*b-3+g)))/y**2)-(g**3)*w*(a**(-2*g))/3)/(2*(1-g-0.166*(g**2)*w*(a**(-2*g))))-2*(c**2)*(1-1/(2*rc*y)))*a
    return dydz

def new_calculation(n):
    yn = odeint(HDE,y0,[z0,z[n]])  # z[n] takes values from new list
    yyn=yn[-1,0]
    O_Dn=1-O_m-(1/(2*rc*yyn))
    q=quad(ant,0,z[n],args=(O_m,O_Dn))[0]     
    h=log10((1+z[n])*(299000/70)*q)+25     
    fn=(yy[n]-M-h)
    return fn


H0=70
M=2
w=20
b=0.04
O_m=0.27
rc=0.09
c=0.7
for G in range (1,2):
        g=0.1*G  # where is this 'g' used ?

        y0=H0
        z0=0

        f_list = []
        for i in range(2):  # the value '2' reflects matrix size
            f_list.append(new_calculation(i))

        rdag=[f_list]
        rmat=[[f] for f in f_list]

        mm=np.dot(rdag,Cov)
        zz=np.dot(mm,rmat)
        hh=np.linalg.det(zz)*0.000001 

        print('Minimum chi^2 =',hh)

非常感谢。但总数只是一个样本。Xx和yy可能在所有可能的功能中。Ode、intrgrals和。你的代码只是为了求和。问题已经更新了。我希望它能有所帮助