0

I'm doing a comparison between the elements of two matrices and a third matrix (whether two elements from the two first matrices are situated in the same columns of the third matrix together) and if that so, I wanted it to break from the "if" ones the condition is verified but it does not do that even when I break it.

A=np.array([['A','T','W','S'],
 ['H','R','W','Q'],
 ['P','E','Z','A'],
 ['Y','U','O','W'],
 ['T','I','P','V'],
 ['R','A','M','G'],
 ['V','K','J','F']])
PR=np.array(
[['E'],
['R'],
['A'],
['M'],
['K'],
['L']])

CLU=np.array(
  [ ['A','X','A','M'],
   ['R','D','S','L'],
   ['E','F','E','B'],
   ['T','J','R','R'],
   ['L','Y','G','A'],
   ['M','R','H','D'],
   ['P','T','N','C']])
   n=[[],[],[],[]]

for i in range (len(PR)):
     for j in range (0,len(A.T)):
        for u in range (0,7):
           for k in range (0,len(CLU.T)-1):
             if PR[i] in CLU.T[k] and A[u][j] in CLU.T[k]:
                n[k]=np.append(n[k], 1)
                break             
             else:
               
                n[k]=np.append(n[k], 0)
    
              
   print(n) 

'''

  • Do you want to break out of the whole loop if the condition is met? Right now your code would only break for the for k in range (0,len(CLU.T)-1) loop. – Brian Keith Feb 06 '23 at 19:28
  • i want it to break from the for u in range (0, 7) i.e. to passe to the next value of the ''u'' – sahraoui khaoula Feb 06 '23 at 19:37

0 Answers0