我是Python新手,不明白是什么.dtype.
例如:
>>> aa
array([1, 2, 3, 4, 5, 6, 7, 8])
>>> aa.dtype = "float64"
>>> aa
array([ 4.24399158e-314, 8.48798317e-314, 1.27319747e-313,
1.69759663e-313])
Run Code Online (Sandbox Code Playgroud)
我认为dtype是aa的属性,应该是int,如果我赋值aa.dtype = "float64"
那么aa应该成为array([1.0 ,2.0 ,3.0, 4.0, 5.0, 6.0, 7.0, 8.0]).
为什么它会改变它的价值和规模?
这是什么意思?
我实际上是从一段代码中学习的,我应该在这里粘贴它:
def to_1d(array):
"""prepares an array into a 1d real vector"""
a = array.copy() # copy the array, to avoid changing global
orig_dtype = a.dtype
a.dtype = "float64" # this doubles the size of array
orig_shape = …Run Code Online (Sandbox Code Playgroud) 我正在从代码中学习,我对它的一条线感到困惑:
things = [float(arg) for arg in sys.argv[1:]]
Omega_a, Omega_b, Delta_a, Delta_b, \
init_pop_a, init_pop_b, tstep, tfinal = things
Run Code Online (Sandbox Code Playgroud)
我在线搜索并试图了解其sys.arg含义,这是我的理解:
sys.argv[0]文件名sys.argv[1:]也是如此,并且是用户应该给出的其余参数.我不确定我是否理解它,如果它是,那么我不明白为什么它不能这样:
Omega_a = input()
Omega_b = input()
etc...
Run Code Online (Sandbox Code Playgroud)
这两种给出参数的方式有什么区别?
另外,如果我运行代码(按F5),Python shell会给出一个错误,如:
Traceback (most recent call last):
File "C:\Users\testcode.py", line 55, in <module>
init_pop_a, init_pop_b, tstep, tfinal = things
ValueError: need more than 0 values to unpack
Run Code Online (Sandbox Code Playgroud)
sys.argv[1:]在给我一个错误之前,我甚至没有机会给出参数().所以我在网上搜索.看起来我需要在cmd中运行这个代码,这让我更加困惑,为什么要这样做以及我应该如何运行cmd才能运行它?
我是一个python初学者,目前使用scipy odeint来计算耦合的ODE系统,但是,当我运行时,python shell总是告诉我
>>>
Excess work done on this call (perhaps wrong Dfun type).
Run with full_output = 1 to get quantitative information.
>>>
Run Code Online (Sandbox Code Playgroud)
所以,我必须改变我的时间步和最后时间,以使其可以整合.要做到这一点,我需要尝试不同的组合,这是非常痛苦的.谁能告诉我如何才能odeint自动改变成功整合这个颂歌系统的时间步长和最终时间?
这是调用odeint的代码的一部分:
def main(t, init_pop_a, init_pop_b, *args, **kwargs):
"""
solve the obe for a given set of parameters
"""
# construct initial condition
# initially, rho_ee = 0
rho_init = zeros((16,16))*1j ########
rho_init[1,1] = init_pop_a
rho_init[2,2] = init_pop_b
rho_init[0,0] = 1 - (init_pop_a + init_pop_b)########
rho_init_ravel, params = to_1d(rho_init)
# perform the integration …Run Code Online (Sandbox Code Playgroud) 我无法解决光学bloch方程,这是一个具有复数值的一阶ODE系统.我发现scipy可以解决这样的系统,但是他们的网页提供的信息太少而且我很难理解.
我有8个耦合的一阶ODE,我应该生成一个函数,如:
def derv(y):
compute the time dervative of elements in y
return answers as an array
Run Code Online (Sandbox Code Playgroud)
然后做 complex_ode(derv?
我的问题是:
complex_ode() 需要jacobian,我不知道如何开始构建一个它应该是什么类型?这是scipy的complex_ode链接:http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.complex_ode.html
任何人都可以向我提供更多信息,以便我可以学到更多.