Python 基于boolen条件将theano张量转换为0和1的张量

Python 基于boolen条件将theano张量转换为0和1的张量,python,theano,Python,Theano,我试图把一个theano张量转换成一个0的张量和一个基于大于0的值的张量。这样做对吗 tensor = tensor > 0 谢谢您正在查找命令gt(表示大于)。其工作原理如下: from theano import tensor as T X = T.dvector('X') f = theano.function([X],T.gt(X,0)) x = np.random.randint(0,10,5) print x # prints [4 0 5 9 5] print f(x)

我试图把一个theano张量转换成一个0的张量和一个基于大于0的值的张量。这样做对吗

tensor = tensor > 0

谢谢

您正在查找命令
gt
(表示大于)。其工作原理如下:

from theano import tensor as T
X = T.dvector('X')
f = theano.function([X],T.gt(X,0))
x = np.random.randint(0,10,5)
print x  # prints [4 0 5 9 5]
print f(x)  # prints [True False True True True]

因为我只需要另一个张量,我认为T.gt(X,0)应该足够了,对吗?是的。这就是你所需要的。我使用了
theano.function
和其他内容来向您展示它是如何工作的。