theano - print value of TensorVariable

后端 未结 5 2010
夕颜
夕颜 2020-12-29 19:02

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

5条回答
  •  鱼传尺愫
    2020-12-29 19:23

    If y is a theano variable, y.shape will be a theano variable. so it is normal that

    print y.shape
    

    return:

    Shape.0
    

    If you want to evaluate the expression y.shape, you can do:

    y.shape.eval()
    

    if y.shape do not input to compute itself(it depend only on shared variable and constant). Otherwise, if y depend on the x Theano variable you can pass the inputs value like this:

    y.shape.eval(x=numpy.random.rand(...))
    

    this is the same thing for the sum. Theano graph are symbolic variable that do not do computation until you compile it with theano.function or call eval() on them.

    EDIT: Per the docs, the syntax in newer versions of theano is

    y.shape.eval({x: numpy.random.rand(...)})
    

提交回复
热议问题