C++ for each, pulling from vector elements

For next examples assumed that you use C++11. Example with ranged-based for loops: You should use const auto &attack depending on the behavior of makeDamage(). You can use std::for_each from standard library + lambdas: If you are uncomfortable using std::for_each, you can loop over m_attack using iterators: Use m_attack.cbegin() and m_attack.cend() to get const iterators.

numpy matrix vector multiplication

Simplest solution Use numpy.dot or a.dot(b). See the documentation here. This occurs because numpy arrays are not matrices, and the standard operations *, +, -, / work element-wise on arrays. Note that while you can use numpy.matrix (as of early 2021) where * will be treated like standard matrix multiplication, numpy.matrix is deprecated and may … Read more