How can I print the numerical value of a theano TensorVariable? I\'m new to theano, so please be patient :)
I have a function where I get y
Use theano.printing.Print to add print operator to your computational graph.
Example:
import numpy
import theano
x = theano.tensor.dvector('x')
x_printed = theano.printing.Print('this is a very important value')(x)
f = theano.function([x], x * 5)
f_with_print = theano.function([x], x_printed * 5)
#this runs the graph without any printing
assert numpy.all( f([1, 2, 3]) == [5, 10, 15])
#this runs the graph with the message, and value printed
assert numpy.all( f_with_print([1, 2, 3]) == [5, 10, 15])
Output:
this is a very important value __str__ = [ 1. 2. 3.]
Source: Theano 1.0 docs: “How do I Print an Intermediate Value in a Function?”