How do I apply a python function by name? I have a list containing the activation function names to apply to each of the hidden layers of a NN.  I want to modify the following command so that instead of relu, the command calls activation[i]:  #activation = ['relu','softplus','softsign'] for i in range (1,hidden_layers+1):     W_dmd[i] = tf.Variable(tf.initializers.GlorotUniform()(shape=[input_shape,code_length]))     b_encoder_dmd[i] = tf.Variable(tf.initializers.Zeros()(shape=[code_length]))     x_dmd[i] = tf.compat.v1.nn.relu(tf.compat.v1.nn.xw_plus_b(x_dmd[i-1], W_dmd[i], b_encoder_dmd[i])) #Instead of relu, same command but with the name in activation[i]   The commands should then be:  x_dmd[1] = tf.compat.v1.nn.relu(tf.compat.v1.nn.xw_plus_b(x_dmd[0], W_dmd[1], b_encoder_dmd[1]))  x_dmd[1] = tf.compat.v1.nn.softplus(tf.compat.v1.nn.xw_plus_b(x_dmd[1], W_dmd[2], b_encoder_dmd[2])) x_dmd[3] = tf.compat.v1.nn.softsign(tf.compat.v1.nn.xw_plus_b(x_dmd[2], W_dmd[3], b_encoder_dmd[3]))   From this , I can come up with:  x_dmd[i] = getattr(tf.compat.v1.nn, activation[i])(tf.compat.v1.nn.xw_plus_b(x_dmd[i-1], W_dmd[i], b_encoder_dmd[i]))   Is this correct? Thanks!
Calling a function of a module by using its name (a string) What is the best way to go about calling a function given a string with the function's name in a Python program.  For example, let's say that I have a module foo, and I have a string whose content is "bar". What is the best way to call foo.bar()?  I need to get the return value of the function, which is why I don't just use eval. I figured out how to do it by using eval to define a temp function that returns the result of that function call, but I'm hoping that there is a more elegant way to do this.
Is there a test for the different styles within maths mode?  What I really want is to be able to save the current style to reinvoke it later on, but a \if along the lines of \ifmmode would work just as well.  In the specific example, I want to measure how big something will be when displayed in maths mode, so I do:  \settoheight{\mathheight}{some bit of maths}   except that it complains because the some bit of maths gets put in a box and measured, and the box doesn't know that it's maths.  So instead I put:  \settoheight{\mathheight}{\(some bit of maths\)}   except that then I get the wrong answer if this is used in displayed maths.  So ideally, I want:  \ifdisplaystyle  \let\currentstyle\displaystyle \else  \iftextstyle   \let\currentstyle\textstyle  ...  \fi \fi \settoheight{\mathheight}{\(\currentstyle some bit of maths\)}   and then I'll be happy.  Is there such a test?    Okay, so \mathchoice is clearly the way to go (thanks Martin!), but its behaviour is a little odd and since I want to use it to define a macro depending on which mode I'm in, this oddity is quite important.  Here's the code:  \newcommand{\mathtest}{% \gdef\name{a}% \mathchoice{% \name \gdef\name{b}% }{% \name \gdef\name{c}% }{% \name \gdef\name{d}% }{% \name \gdef\name{e}% }% \name}  \[ \mathtest \]   If \mathchoice behaved like \if, this ought to print ab.  But it prints ae.  All the options to \mathchoice get processed (which makes me wonder a bit how it works, but that's by-the-by).  So, is there an obvious way to make \mathchoice behave a little more like \if? How can I add a bookmark in my nautilus folder explorer Programmatically, how does "rooting" a device enable access? Let $x_0 \in \mathbb{R}$ and $f,g: \mathbb{R} \to \mathbb{R}$  such that $f$ is discontinuous at $x_0$ but $g$ is continuous at $x_0$, then $f+g$ at $x_0$ is...   My approach: After some graphical attempts to construct such a pathological case as given above I claim that the described scenario isn't possible. That is $$f \text{ disc. at } x_0 \text{ and } g \text{ cont. at } x_0 \implies f+g \text{ disc. at } x_0 $$  Proof: I was trying to come up with a contradiction, because if they happen to work out I find these kind of proofs to be most satisfying.   Assume $f+g$ is continuous at $x_0$ that is $$\forall \epsilon &gt; 0 ,\exists \delta_1 &gt; 0 : \forall x \in \mathbb{R}, |x-x_0| &lt; \delta_1 \implies |f(x)+g(x)-f(x_0)-g(x_0)| &lt; \epsilon  $$  Since this statement must be true for all $\epsilon &gt; 0$ I could choose $\epsilon:=1$. Next I know that also $g$ is continuous at said point $x_0$, thus  $$\forall \epsilon &gt; 0, \exists \delta_2 &gt; 0 : \forall x \in \mathbb{R}, |x-x_0| &lt; \delta_2 \implies |g(x)-g(x_0)| &lt; \epsilon $$  and I have that $f$ is NOT continuous at $x_0$ therefore: $$\exists \epsilon^* &gt; 0, \forall \delta&gt;0: \exists x \in  \mathbb{R}, |x-x_0| &lt; \delta \wedge |f(x)-f(x_0)| \geq \epsilon $$  My problem is to bring all these three statements nicely together. Mainly I get confused by the quantors. In order to match all three statements I assume I have to choose $\epsilon &gt; 0$ such that the last statement is met, so say $\epsilon:= \epsilon^*&gt;0$, so statement 1 and 2 are still true for said $\epsilon$  I also need to choose $\delta$. Lets say $\delta = \min{(\delta_1,\delta_2)}$ now I should be able to work with all three statements at the same time right? But then I stumble with my argumentation.  Let $|x-x_0|&lt; \delta$, then we obtain $$ |f(x)+g(x)-f(x_0)-g(x_0)| \leq |f(x)-f(x_0)| + |g(x)-g(x_0)| &lt; - \epsilon + \epsilon =0 $$ which means that $|f(x)+g(x)-f(x_0)-g(x_0)| &lt;0$ and I hope that this is a contradiction because $|.| \geq 0$. Please comment (or answer) if I am right or absolutely on the wrong path. I'd also appreciate it if you criticize my formulation. How do I completely reset network settings? PHP syntax for dereferencing function result Why is my query suddenly slower than it was yesterday? [Salutations]  (check one)  [ ] Well trained professional, [ ] Casual reader, [ ] Hapless wanderer,   I have a (check all that apply)  [ ] query [ ] stored procedure [ ] database thing maybe     that was running fine (if applicable)   [ ] yesterday [ ] in recent memory [ ] at some point    but is suddenly slower now.  I've already checked to make sure it's not being blocked, and that it's not the victim of some long running maintenance task, report, or other out of band process.  What is the problem, what should I do, and what information can I provide to get some help?  [*Insert appropriate closing remarks*] Continuous function does not map closed set to closed set Vim-latex adds extra brackets when typing empty brackets Irreducibility of reciprocal polynomials Given that  $f(x)=\sum\limits_{k=0}^n a_kx^k$ is an irreducible polynomial, show that $g(x)=\sum\limits_{k=0}^n a_kx^{n-k}$ is irreducible too. I don't see how this specific coefficient exchange would preserve the irreducibility. Is there something else I should be looking at? Piping for loop output prevents local variable modification Basically asking what were the motives behind each theory. What was it that led physicists toward these ideas? in QGis 1.8 were lots of predefined coordinate systems (national projections). Where have they all gone in qgis 2.0? I specifically need the Gauß-Krüger-Projections Zone 1 to 5.  Is there any plugin to load those coordinate systems? How SELECT column does not list in GROUP BY clause The query:  select year,sum(mark),sum(maxmark)  from table1  group by parameterno   yields an error message:     Column 'table1.year' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Totally disconnected space that is not $T_2$ Why does the square root of a square involve the plus-minus sign? If $\sqrt{x^2}$ can be simplified as follows:  $\sqrt{x^2} = (x^2)^\frac{1}{2} = x^{\frac{2}{1}\times\frac{1}{2}} =x^\frac{2}{2} = x^1 = x$  Then why would $\sqrt{x^2} = \pm x$? Given $n+1$ points in the plane, Lagrangian interpolation gives the unique polynomial of degree less or equal to $n$.  From the examples I've seen so far, interpolation polynomials all have degree exactly $n$ but I don't know if there might be a set of points for which the interpolation gives a polynomial of degree strictly less than $n$.  Many thanks for your answers. When I run sudo, what exactly happens to my environment?  When I run sudo command, it doesn't seem to see my or root's environment. For example, my path for both includes /usr/local/bin, but if I try to run one of the program's without the full path, it fails.  I thought sudo ran as root, and hence got root`s environment. Is there a different way that bash executes under sudo than under root or my normal user?  EDIT:  I have been using sudo -i lately, but recently it has been causing problems because my current working directory gets set to /root. This is as expected (sorta), but I still don't understand why sudo isn't recognizing my executables in /usr/local/bin.  EDIT:  I am running Fedora 15. I'm a web developer, started to become a web designer. However, I think my understanding of colors is not practical yet. There are tools out there that can give you color harmonies, and more stuff, like , but they don't give you the start point. I mean, how should I know that for this web site, I'd better use green and for that website, choose red. How should I know that?  I think color selection is more like an art, instead of being a science, and I'm like "you should become an color artist, in order to become a web designer".  How can I improve my color selection skill? A native speaker said: "I have ever went to" I heard a guy from Manchester, UK said &mdash;     It was the best restaurant I have ever went to.   And Google offers 23 million pages for the query "have ever went to", and only 3 millions for "I have ever gone to".  Is this form correct? Has the grammar changed?