小编vah*_*ndi的帖子

使用python的输入库指定多个可能的类型

我想指定类型提示的功能,可以接收无论是liststrS或A listint秒.有没有办法用Python做到这一点?就像是:

from typing import List

def my_function(list_arg: List[str|int]):

    ...
    ...
Run Code Online (Sandbox Code Playgroud)

python function typing data-structures

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

将numpy函数转换为theano

我正在PyMC3计算一些我不会在这里讨论的内容,但是如果您有兴趣的话,可以从此链接中了解。

“ 2-lambdas”情况基本上是一个开关函数,需要将其编译为一个Theano函数以避免dtype错误,并且看起来像这样:

import theano
from theano.tensor import lscalar, dscalar, lvector, dvector, argsort

@theano.compile.ops.as_op(itypes=[lscalar, dscalar, dscalar], otypes=[dvector])
def lambda_2_distributions(tau, lambda_1, lambda_2):
        """
        Return values of `lambda_` for each observation based on the 
        transition value `tau`.
        """
        out = zeros(num_observations)
        out[: tau] = lambda_1  # lambda before tau is lambda1
        out[tau:] = lambda_2  # lambda after (and including) tau is lambda2
        return out
Run Code Online (Sandbox Code Playgroud)

我试图将其推广到适用于'n-lambdas'的地方taus.shape[0] = lambdas.shape[0] - 1,但是我只能提出这种极其缓慢的numpy实现。

@theano.compile.ops.as_op(itypes=[lvector, …
Run Code Online (Sandbox Code Playgroud)

python numpy theano pymc3

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

标签 统计

python ×2

data-structures ×1

function ×1

numpy ×1

pymc3 ×1

theano ×1

typing ×1