Vectorizing a for loop that uses a Skfuzzy controller

29 Views Asked by At

I am new to programming and vectorizing for loops. I have a loop that I use to iterate over all of my input values, then I input them into three Scipy SKfuzzy controllers I built, but it is really slow to compute the results with the array sizes I am using. I think this is a use case for vectorization, since the data is already in a numpy array.

strm_vul = []
for i in range(len(dist_x)):
    vulnerability.input['strmdist'] = dist_x[i] # input array of 'strmdist' float values to controller
    vulnerability.input['strmord'] = order_x[i] # input array of 'strmord' integers to controller
    vulnerability.input['slope'] = slope_x[i]   # input array of 'slope' float values to controller
    vulnerability.compute()
    strm_vul.append(vulnerability.output['vul']) # computing 'vul' value from controllers using defined rules

I am not sure on where to start with vectorizing code with the skfuzzy controller. The output of the for loop is just an array of values like this:

[0.16915977085901757, 0.1569052664939388, 0.15609296737587938, 0.15637821547517086]

0

There are 0 best solutions below