如何在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  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))

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注