[theano]入门-变量相加、矩阵声明

时间:2022-12-12 14:35:18
#作为python新手,可能学习的东西比较多,注意如果两个矩阵相乘的话,跟matlab区别还是挺大的
#
!/usr/bin/env python # coding=utf-8 #格式一般用import ss as d import theano.tensor as T from theano import function import numpy as np #声明变量 x=T.dscalar('x') y=T.dscalar('y') z=x+y f=function([x,y],z) #call the function f(2,3) print f(2,3) #declare the varalble x=T.dmatrix('x') y=T.dmatrix('y') z=x+y f=function([x,y],z) c=f([[1,2],[3,5]],[[1,3],[3,5]]) print c[0,0] #shape function will return the size of a array d=np.shape(c) print d a=3 b=2 #** means mici c=a**2 print c a=T.vector() out=a**10 f=function([a],out) print f([1,2,3])