alternative for speed #3
-
Nice simulation, wonder why didnt use numpy arrays to get rid of the loops / lists. and use matplotlib Animation class for realtime animation. example heat equation |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You cannot take advantage of NumPy arrays in a trivial way here because you need to compute the interaction with each particle with the others individually. The best solution for speed is just rewriting the code with C++. There is also an algorithm called "Sweep and Prune" that can also be used to avoid evaluating a lot of collisions and offer a speed boost, but it's going to make the implementation a bit more complex. You can replace matplotlib Animation with the slider. Personally for testing, I prefer the slider, because it allows me to see the position of the particles at any moment. Thank you :) |
Beta Was this translation helpful? Give feedback.
You cannot take advantage of NumPy arrays in a trivial way here because you need to compute the interaction with each particle with the others individually. The best solution for speed is just rewriting the code with C++. There is also an algorithm called "Sweep and Prune" that can also be used to avoid evaluating a lot of collisions and offer a speed boost, but it's going to make the implementation a bit more complex.
You can replace matplotlib Animation with the slider. Personally for testing, I prefer the slider, because it allows me to see the position of the particles at any moment.
Thank you :)