title: How to use 'input' to input mathematical functions as variables in python 3.x
body: <p>I want the user of my program to input a mathematical function of their choosing in numpy notation so that I can operate on it. For example:</p>
  
  <pre><code>import numpy as np
  f=eval(input("Please input your function in numpy notation")
  
  &gt;&gt;&gt; "Please input your function in numpy notation"
  &gt;&gt;&gt; np.exp(x)
  &gt;&gt;&gt; NameError: name 'x' is not defined
  </code></pre>
  
  <p>with the code above, the user is inputting the exponential function, which is saved to a variable 'f' - more generally, I would like any mathematical function to be given as input and for it to be stored somehow as a python function. Pseudocode for this may be something like:</p>
  
  <pre><code>def F(x):
      f = eval(input("Please enter function in numpy notation:"))
      return f
  </code></pre>
  
  <p>which, if we use the exponential function again as an example, would be equivalent to hard coding:</p>
  
  <pre><code>def F(x):
      return np.exp(x)
  </code></pre>
  
  <p>One more example for clarity.</p>
  
  <pre><code>def F(x):
      f = eval(input("Please enter function in numpy notation:"))
      return f
  
  &gt;&gt;&gt; x*np.sin(x)
  </code></pre>
  
  <p>The user input x*np.sin(x) on the command line, which is equivalent to hard coding:</p>
  
  <pre><code>def F(x):
      return x*np.sin(x)
  </code></pre>
  
  <p>Is there anyway to do this?</p>