I'm trying to find find the value of
s=max(ele, 0)
element-wise on a matrix in theano.
I don't have much experience with theano.
So far I have
x = theano.tensor.dmatrix('x')
s = (x + abs(x)) / 2 # poor man's trick
linmax = function([x], s)
This works, but isn't pretty and I thought I should be able to use theano.tensor.maximum
for this.
In matlab, to do what I want to do, I would just write
linmax=@(x) max (x, zeros (size (x)))
This works for me:
import theano.tensor as T
from theano import function
x = T.dmatrix('x')
linmax = function([x], T.maximum(x,0))
Testing:
linmax([[-1,-2],[3,4]])
Outputs:
array([[0.,0.],[3.,4.]])
I have seen this implemented as
s = x*(x>0)
several times. Dont know if that's faster than T.maximum()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With