小编use*_*157的帖子

什么是.dtype呢?

我是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)

python numpy

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

'sys.argv'是什么意思?

我正在从代码中学习,我对它的一条线感到困惑:

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 cmd sys argv

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

如何让odeint成功?

我是一个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)

python scipy

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

scipy中复杂的ODE系统

我无法解决光学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?

我的问题是:

  1. 我的y不是一个列表而是一个矩阵,我如何给出一个适当的输出适合complex_ode()?
  2. complex_ode() 需要jacobian,我不知道如何开始构建一个它应该是什么类型?
  3. 我应该把正常的ode和time linspace中的初始条件放在哪里?

这是scipy的complex_ode链接:http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.complex_ode.html

任何人都可以向我提供更多信息,以便我可以学到更多.

python scipy ode

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

标签 统计

python ×4

scipy ×2

argv ×1

cmd ×1

numpy ×1

ode ×1

sys ×1