Python 在theano中得到张量的值

Python 在theano中得到张量的值,python,theano,Python,Theano,在我的程序中,我想使用张量的形状值。例如,张量x的形状为(3,4,5)。我想得到4的值,我尝试了以下方法: t=x.shape[1] #returns a scalar t=x.shape[1].eval() #returns a array(4) 如何获得4的值,我需要的是int类型,而不是标量或其他类型。请尝试以下方法: import numpy as np int(np.asscalar(x.shape[1].eval())) 请尝试以下方法: import numpy as np i

在我的程序中,我想使用张量的形状值。例如,张量x的形状为(3,4,5)。我想得到4的值,我尝试了以下方法:

t=x.shape[1] #returns a scalar
t=x.shape[1].eval() #returns a array(4)
如何获得4的值,我需要的是int类型,而不是标量或其他类型。

请尝试以下方法:

import numpy as np
int(np.asscalar(x.shape[1].eval()))
请尝试以下方法:

import numpy as np
int(np.asscalar(x.shape[1].eval()))
我使用x.shape[1].eval()[1]最后得到4我使用x.shape[1].eval()[1]最后得到4