通过几个函数后参数更改-Python

时间:2019-07-02 16:23:16

标签: python

我的代码中有一件奇怪的事,我从未见过,我使用了一个函数,该函数调用相互构建的多个函数,如果我看一个参数,那是np.ndarray开始时就变成了float列表,请参见下面的代码示例:

在main.py中,我有:

mean_D(z,lb,ld,B,r, 'x',0)

在functions_traitement_multiple_trace.py中:

def mean_D(z,lb,ld,B,r, mode,offset = 0):
...
 if mode == 'z':
        print(str(type(z)) + '1' )
        from fit_functions import intdx
        try : 
            return quad(intdx, 1e-11, 5e-6 ,
                        args=(abs(lb),abs(ld),abs(B),abs(r),offset))[0]
                        /(4e-21/(6*np.pi*0.001*abs(r)))
        except(ZeroDivisionError):
            return 10

在fit_functions.py中:

@jit
def intdx(z,lb,ld,B,r,offset=0):
    print(str(type(z)) + '2')
    return Boltzman(z,abs(lb),abs(ld),abs(B))
                    *4e-21/(6*np.pi*eta_x(z,r,offset)*r) 

在同一文件中,我添加到Boltzman函数中:

print(str(type(z)) + '3')

输出给我:

<class 'numpy.ndarray'>1
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3
<class 'float'>2
<class 'float'>3

我真的不明白这里发生了什么,我尝试了使用和不使用numba的情况,它返回了相同的输出。

该函数返回我需要的东西,但我想在Boltmann函数中添加一个for循环,我得到了以下输出:

<class 'numpy.ndarray'>1
<class 'float'>2
<class 'float'>3
Traceback (most recent call last):

  File "<ipython-input-15-f859197ca9df>", line 1, in <module>
    mean_D(z,lb,ld,B,r, 'x',0)

  File "C:\Users\maxim\ownCloud\Thèse\code_python\Traitement_multiple_trace\functions_traitement_multiple_trace.py", line 121, in mean_D
    return quad(intdx, 1e-11, 5e-6 , args=(abs(lb),abs(ld),abs(B),abs(r),offset))[0]/(4e-21/(6*np.pi*0.001*abs(r)))

  File "C:\Users\maxim\Anaconda3\envs\holopy_env2\lib\site-packages\scipy\integrate\quadpack.py", line 341, in quad
    points)

  File "C:\Users\maxim\Anaconda3\envs\holopy_env2\lib\site-packages\scipy\integrate\quadpack.py", line 448, in _quad
    return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)

TypeError: object of type 'float' has no len()

有人已经有类似的东西吗?

0 个答案:

没有答案