Theano简单入门(二)

一、Theano的基本用法

定义函数的方式:

步骤 0    宣告使用theano   import theano
步骤 1    定义输入       x=theano.tensor.scalar() 这里相当于tensorflow的placeholder
步骤 2    定义输出       y=2*x
步骤3     定义fuction    f = theano.function([x],y)
步骤 4    调用函数     print f(-2)

步骤1 定义输入变量 

      a = theano.tensor.scalar()

      b =theano.tensor.matrix()

简化  import  theano.tensor as T

步骤2 定义输出变量 需要和输入变量的关系

     x1=T.matrix()

     x2=T.matrix()

     y1=x1*x2

     y2=T.dot(x1,x2) #矩阵乘法

步骤3 申明函数

     f= theano.function([x],y)

    函数输入必须是list 带[]

例如:

# -*- coding: UTF-8 -*-
import numpy as np
import theano.tensor as T
from theano import function

# basic
x = T.dscalar('x') # 建立标量x的容器,类似于tf.placeholder,但是直接标明了类型
y = T.dscalar('y') # 建立标量y的容器
z = x + y
# function first:imput sconed:output
#
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值