Don't use the Python "and" operation. Use theano.tensor.and(a,b) instead. I think it will fix your problem.
Le mer. 28 juin 2017 10:26, Sym <mass.comi...@gmail.com> a écrit : > > I want to build a piecewise function with theano, for instance a function > that is nonzero only in the interval [2,3]. > > Here is the minimal code reproducing the error : > > > import theano > import theano.tensor as T > import numpy as np > import matplotlib.pyplot as plt > > r = T.scalar() > gate = T.switch( T.ge(r,2.) and T.le(r,3.) , 1., 0.) > f = theano.function([r],gate) > x = np.arange(0.,4.,0.05,dtype='float32') > y = [f(i) for i in x] > plt.plot(x,y) > > > > The result is the following : https://i.stack.imgur.com/XMQme.png > > Which is clearly not correct : only one condition is satisfied here. > > > If I replace T.switch by theano.ifelse.ifelse the result is the same... > > Is it a known bug, or am I missing something here? > > > Thanks a lot ! > > -- > > --- > You received this message because you are subscribed to the Google Groups > "theano-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to theano-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.