title: Python: Applying arithmetic operators on list like on numpy.ndarray?
body: <p>here's my first code, using numpy.linspace method:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  
  def graph(formula, string, x1, x2):
      x = np.linspace(x1, x2)
      y = formula(string, x)
      plt.plot(x, y)
  
  
  def my_formula(string, x):
      return eval(string)
  
  
  graph(my_formula, "2 * (x ** 3) - 9.5 * (x ** 2) + 10.5 * x", 0, 3)
  plt.tight_layout()
  plt.show()
  </code></pre>
  
  <p>it works fine, however, instead of importing numpy, if I do this:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  
  class Module:
      @staticmethod
      def linspace(finish, slices, start=0):
          each = float((finish - start) / (slices - 1))
          res = list()
          for i in range(slices):
              res.append(start + i * each)
          return res
  
  
  def graph(formula, string, x1, x2):
      x = Module.linspace(x2, 50, start=x1)
      y = formula(string, x)
      plt.plot(x, y)
  
  
  def my_formula(string, x):
      return eval(string)
  
  
  graph(my_formula, "2 * (x ** 3) - 9.5 * (x ** 2) + 10.5 * x", 0, 3)
  plt.tight_layout()
  plt.show()
  </code></pre>
  
  <p>Here's a error shows up:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:/Users/QINY/PycharmProjects/begin/covid/seven.py", line 24, in &lt;module&gt; graph(my_formula, "2 * (x ** 3) - 9.5 * (x ** 2) + 10.5 * x", 0, 3)
  File "C:/Users/QINY/PycharmProjects/begin/covid/seven.py", line 16, in graph y = formula(string, x) File "C:/Users/QINY/PycharmProjects/begin/covid/seven.py", line 21, in my_formula return eval(string)
  File "&lt;string&gt;", line 1, in &lt;module&gt; TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
  </code></pre>
  
  <p>Can anyone explain how it is done in numpy.adarray, to automatically iterate the list? </p>