I am trying to define a function that contains an inner loop for simulating an integral.
The problem is speed. Evaluating the function once can take up to 30 seconds on
The "fundamental mistake" is that you expect good performance in long loops from Python. It's an interpreted language, and switching between implementations and ctyping does nothing to this. There are a few numeric Python libraries for fast computing, mosly written in C. For example, if you already use numpy for arrays, why not you go further and use scipy for your advanced math? It will increase both readability and speed.