python中arcsec_在Python类中继承Cython类

我有两个用cython编写的类,我想在python中的一个类中使用它们。在

位置.pyximport numpy as np

cimport numpy as np

cimport cython

cpdef double std_G,v=4.3e-9, 299792.458

cdef class cosmo(object):

cdef public double o_m, o_l, h, w, o_r, G, v

def __init__(self,double o_m = 0.3, double o_l = 0.7, double h = 0.7, double w = -1, double o_r = 0., double G = std_G):

self.o_m = o_m

self.o_l = o_l

self.o_r = o_r

self.h = h

self.w = w

self.G = G

self.v = v

def __copy__(self):

return cosmo(o_m = self.o_m, o_l = self.o_l, h = self.h, w = self.w, o_r = self.o_r, G = self.G)

property H0:

def __get__(self):

return 100*self.h

property M_solar:

def __get__(self):

return 1.989e30

property Mpc_to_m:

def __get__(self):

return 3.0856e22;

def hubble2(self, double z):

cdef double inv_a

inv_a = 1.+z

return (self.o_r*inv_a**4 + self.o_m*inv_a**3 + \

self.o_l*(inv_a**(3*(1+self.w))) + (1 - self.o_m - self.o_l - self.o_r)*inv_a**2)*self.H0**2

property hubble_length:

def __get__(self):

return self.v / self.H0

def rc(self, double z):

return 3.*self.hubble2(z)/(8*np.pi*self.G)

cdef class PositionsD(object):

cdef double [:] _x

property x:

def __get__(self):

return np.array(self._x)

def __set__(self, np.ndarray[DTYPE_T, ndim=1] x):

self._x = x

cdef double [:] _y

property y:

def __get__(self):

return np.array(self._y)

def __set__(self, np.ndarray[DTYPE_T, ndim=1, mode='c'] y):

self._y = y

def __init__(self, np.ndarray[DTYPE_T, ndim=2, mode='c'] positions):

self._x = positions[:,0]

self._y = positions[:,1]

虽然我想在modelfit类中使用PositionsD类,而modelfit将继承{}的属性:

^{pr2}$

但我收到以下错误消息:>>> x=np.array([[0.3,-0.1],[1,3.4]])

>>> mf=modelfit(x)

Traceback (most recent call last):

File "", line 1, in

TypeError: __init__() takes exactly 1 argument (2 given)

我不知道我做错了什么。有什么建议吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值