I am trying to vectorize a for loop that I have inside a class method. The for loop has the following form: it iterates through a bunch of points and depending on whether a certain variable is true (called "self.condition_met"), it calls a couple of functions at a point and adds the result to the list. Each point here is an element in a vector lists, that is, a data structure that looks like an array ([[1,2,3], [4,5,6], ...]). Here is the problematic function:
def myClass: def my_inefficient_method(self): final_vector = []
self.condition_met is set before my_inefficient_method is called, so you don't need to check it every time, but I'm not sure how best to write this. Since there are no destructive operations here, it looks like I could rewrite this whole thing as a vector operation - is this possible? any ideas how to do this?
source share