Python 如何将矩阵或向量打印到由函数返回的屏幕上?

Python 如何将矩阵或向量打印到由函数返回的屏幕上?,python,machine-learning,theano,Python,Machine Learning,Theano,我是theano的新手,当我尝试运行此代码时,我得到以下响应: 1 import numpy 2 import theano 3 import theano.tensor as T 4 rng = numpy.random 5 6 N = 5 7 feats = 3 8 D = (rng.randn(N, feats), rng.randint(size=N, low=0, high=10)) 9 training_steps = 10000 10 1

我是theano的新手,当我尝试运行此代码时,我得到以下响应:

  1 import numpy
  2 import theano
  3 import theano.tensor as T
  4 rng = numpy.random
  5 
  6 N = 5
  7 feats = 3
  8 D = (rng.randn(N, feats), rng.randint(size=N, low=0, high=10))
  9 training_steps = 10000
 10 
 11 # Declare Theano symbolic variables
 12 x = T.matrix("x")
 13 y = T.vector("y")
 14 w = theano.shared(rng.randn(feats), name="w")
 15 b = theano.shared(0., name="b")
 16 print "Initial model:"
 17 # Construct Theano expression graph
 18 print T.dot(x, w)
初始模型: dot.0


我如何才能真正看到返回值的值,谢谢。

您需要对表达式求值,最好将其转换为函数。从代码中删除第18行,然后添加

dot_product = T.dot(x, w)
f = theano.function([x], dot_product)

print f(rng.randn(feats))