theano 地圖和減少

theano.maptheano.scan_module.reducetheano_scan 的包裝。他們可以被視為 scan 的殘疾人版本。你可以檢視基本掃描用法部分以供參考。

import theano
import theano.tensor as T
s_x = T.ivector()
s_sqr, _ = theano.map(
    fn = lambda x:x*x,
    sequences = [s_x])
s_sum, _ = theano.reduce(
    fn = lambda: x,y:x+y,
    sequences = [s_x],
    outputs_info = [0])
fn = theano.function([s_x], [s_sqr, s_sum])
fn([1,2,3,4,5]) #[1,4,9,16,25], 15