zoukankan      html  css  js  c++  java
  • theano入门教程1.4

    使用共享变量


    # -*- coding: utf-8 -*-

    """

    Created on Wed Jun  4 23:28:21 2014


    @author: wencc

    """


    from theano import shared

    from theano import function

    import theano.tensor as T


    if __name__ == '__main__':

    state = shared(0)

    inc = T.iscalar('inc')

    accumulator = function([inc], state, updates=[(state, state+inc)])

    print state.get_value()

    print accumulator(1)

    print state.get_value()

    print accumulator(20)

    print state.get_value()

    fn_of_state = state*2 + inc

    foo = T.scalar(dtype=state.dtype)

    skip_shared = function([inc, foo], fn_of_state, givens=[(state, foo)])

    skip_shared(1, 3)

    state.get_value()



    shared函数构造共享变量,共享变量的get_value,set_value函数用来查看和设置共享变量的值

    function函数中的updates参数用来更新共享变量,它是一个list,list中的每一项用map(共享变量,共享变量的新值表达式)的形式来表示。









  • 相关阅读:
    ContentProvider
    铃声设置
    TTS技术
    http://www.w3cschool.cc/jqueryui/jqueryui-tutorial.html
    HttpHelper
    .net面试题
    函数和原型
    关于递增运算符
    CSS学习笔记
    CSS/CSS3 如何实现元素水平居中
  • 原文地址:https://www.cnblogs.com/fireae/p/3772511.html
Copyright © 2011-2022 走看看