小编Wol*_*orf的帖子

py.test参数化测试类

我有一个用于测试我的一些代码的类.我想参数化设置并使用不同的参数重新运行类:

class TestNormalLTEPlasma:


    def setup(self, t=10000):
        self.plasma = plasma.LTEPlasma.from_abundance(t, {'Si':1.0}, 1e-13, atom_data, 10*86400)

    def test_beta_rad(self):
        assert self.plasma.beta_rad == 1 / (10000 * constants.k_B.cgs.value)

    def test_t_electron(self):
        assert self.plasma.t_electron == 0.9 * self.plasma.t_rad

    def test_saha_calculation_method(self):
        assert self.plasma.calculate_saha == self.plasma.calculate_saha_lte
Run Code Online (Sandbox Code Playgroud)

我希望运行这个类从t = 2000到t = 20000,步长为1000

python pytest

15
推荐指数
2
解决办法
7013
查看次数

熊猫沿着多指数和单独的指数切片

我已经开始将Pandas用于一些大型数据集,而且大多数情况下效果非常好.虽然我对这些指数有一些问题

  1. 我有一个有三个级别的MultiIndex - 让我们说a,b,c.如何切割索引a - 我只想要a = 5,7,10,13的值.执行df.ix [[5,7,10,13]]不能像文档中指出的那样工作

  2. 我需要在DF上有不同的索引 - 我可以创建这些多个索引而不将它们与数据帧关联并使用它们来回馈原始的ndarray索引吗?

  3. 我可以单独切片MultiIndex而不是系列或Dataframe吗?

提前致谢

python pandas

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

cython与指针数组

我在python中有一个numpy.ndarrays(具有不同长度)的列表,需要能够非常快速地访问python中的那些.我认为一系列指针可以解决这个问题.我试过了:

float_type_t* list_of_arrays[no_of_arrays]
for data_array in python_list_of_arrays:
    list_of_arrays[0] = data_array
Run Code Online (Sandbox Code Playgroud)

但是cython抱怨:

no_of_arrays < Not allowed in a constant expression
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几种方法来满足这个变量:

cdef extern from *:
    ctypedef int const_int "const int"
Run Code Online (Sandbox Code Playgroud)

(有更多的创造性尝试) - 但不幸的是它不起作用.

请帮忙.

python numpy cython

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

多项式曲面拟合numpy

如何z=f(x,y)在具有完整交叉项的numpy中使用多项式拟合2D曲面?

numpy polynomial-math

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

标签 统计

python ×3

numpy ×2

cython ×1

pandas ×1

polynomial-math ×1

pytest ×1