I have a 1213x5 column array of rows with between 3 and 5 values (see example below).
Example of array:
2 3 6 nan nan
8 6 2 nan nan
9 8 6 5 nan
9 5 2 1 nan
2 3 4 1 6
6 8 5 3 2
I have two values and want to find the index of the rows where the two values appear. I have created the following code however it takes ~0.2 seconds to complete. This is not ideal since I have to iterate over this thousands of times. I'm new to Python and therefore am still getting used to pythonic code and what the quickest way to do things are.
Current code:
def rowIdx(array, m, n):
idxList = []
m = int(m)
n = int(n)
for x in range(len(array)):
if (array[x,0]== m or array[x,0] == n) and (array[x,1] == m or array[x,1] == n):
idxList.append(x)
if (array[x,0] == m or array[x,0] == n) and (array[x,2] == m or array[x,2] == n):
idxList.append(x)
if (array[x,1] == m or array[x,1] == n) and (array[x,2] == m or array[x,2] == n):
idxList.append(x)
if (array[x,0]== m or array[x,0] == n) and (array[x,3] == m or array[x,3] == n):
idxList.append(x)
if (array[x,1] == m or array[x,1] == n) and (array[x,3] == m or array[x,3] == n):
idxList.append(x)
if (array[x,2] == m or array[x,2] == n) and (array[x,3] == m or array[x,3] == n):
idxList.append(x)
if (array[x,0] == m or array[x,0] == n) and (array[x,4] == m or array[x,4] == n):
idxList.append(x)
if (array[x,1]== m or array[x,1] == n) and (array[x,4] == m or array[x,4] == n):
idxList.append(x)
if (array[x,2] == m or array[x,2] == n) and (array[x,4] == m or array[x,4] == n):
idxList.append(x)
if (array[x,3] == m or array[x,3] == n) and (array[x,4] == m or array[x,4] == n):
idxList.append(x)
return idxList
Any help would be much appreciated. Thanks!