Search code examples
pythontheano

Get the value of tensor in theano


In my program, I want to use the shape value of a tensor. For example, the tensor x has shape of (3,4,5). I want to get the value of 4, i tried the way below:

t=x.shape[1] #returns a scalar
t=x.shape[1].eval() #returns a array(4)

how can i get a value of 4, what i want is a type of int, not scalar or other types.


Solution

  • Try this instead:

    import numpy as np
    int(np.asscalar(x.shape[1].eval()))