Python 在Theano中[a<;0]=0的等价物是什么?
在Theano(张量变量)中,NumPy的Python 在Theano中[a<;0]=0的等价物是什么?,python,theano,Python,Theano,在Theano(张量变量)中,NumPy的a[a
a[a<0]=0
等价于什么?
我想要所有小于等于零的数字的矩阵元素。这项工作:
import theano
a=theano.tensor.matrix()
idxs=(a<0).nonzero()
new_a=theano.tensor.set_subtensor(a[idxs], 0)
import theano
a=无张量矩阵()
idxs=(a这也有效,还可以增加上限
import theano
import theano.tensor as T
a = T.matrix()
b = a.clip(0.0)
或者,如果您也想要上限,您可能希望尝试:
b = T.clip(a, 0.0, 1.0)
其中1.0是要设置上限的位置
检查文档文档中的相关位置似乎是“谢谢”。还可以使用“a=T.where(a<0,0,a)”