深度学习的始祖框架,grandfather级别的框架 —— Theano —— 示例代码学习(2)

Angry Panda / 2024-02-12 / 原文

代码1:(if else判断结构)

import theano
from theano import tensor
from theano.ifelse import ifelse

x = tensor.fscalar('x')
y = tensor.fscalar('y')
z = ifelse(x>0, 2*y, 3*y) # x>0的返回值是int8类型
f = theano.function([x,y], z, allow_input_downcast=True)

print( f(1.1, 2.2) )

print( f(-1.1, 2.2) )

运行结果:

image



代码2:(循环:scan)



参考:

https://zhuanlan.zhihu.com/p/24282760