utils.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:NMT 作者: tuzhaopeng 项目源码 文件源码
def as_floatX(variable):
    """
       This code is taken from pylearn2:
       Casts a given variable into dtype config.floatX
       numpy ndarrays will remain numpy ndarrays
       python floats will become 0-D ndarrays
       all other types will be treated as theano tensors
    """

    if isinstance(variable, float):
        return numpy.cast[theano.config.floatX](variable)

    if isinstance(variable, numpy.ndarray):
        return numpy.cast[theano.config.floatX](variable)

    return theano.tensor.cast(variable, theano.config.floatX)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号