美文网首页
数和矩阵相加

数和矩阵相加

作者: 何狗带 | 来源:发表于2017-11-07 16:27 被阅读0次

    1.示例代码

    import numpy

    import theano.tensor as T

    from theano import function

    x = T.dscalar('x')

    y = T.dscalar('y')

    z  = x + y

    f  = function([x, y], z)

    这样,计算x+y可以调用 f([x,y]) 实现

    2.分析

        数据类型

        T.dscalar('x')中dscalar是一种theano类型,并非一个类,Theao的数据都是TensorVariable的实例。常用数据类型有dscalar(数),dvector(向量),dmatrix(矩阵),所有数据类型如下:

    byte:bscalar,bvector,bmatrix,brow,bcol,btensor3,btensor4,btensor5

    16-bit integers:wscalar,wvector,wmatrix,wrow,wcol,wtensor3,wtensor4,wtensor5

    32-bit integers:iscalar,ivector,imatrix,irow,icol,itensor3,itensor4,itensor5

    64-bit integers:lscalar,lvector,lmatrix,lrow,lcol,ltensor3,ltensor4,ltensor5

    float:fscalar,fvector,fmatrix,frow,fcol,ftensor3,ftensor4,ftensor5

    double:dscalar,dvector,dmatrix,drow,dcol,dtensor3,dtensor4,dtensor5

    complex:cscalar,cvector,cmatrix,crow,ccol,ctensor3,ctensor4,ctensor5

        括号中的'x'这个符号命名,可以省略,这个参数可以帮助debug。

        函数定义

        f  = function([x, y], z)

        这个调用中向function传入两个参数,第一个[x,y]是要传入计算公式的的参数,而z则是自定义的计算公式。这样,即可自己对公式进行调整定义自己的函数功能。

    相关文章

      网友评论

          本文标题:数和矩阵相加

          本文链接:https://www.haomeiwen.com/subject/kwejmxtx.html