jeudi 5 décembre 2019

using an array as a conidition in an if loop

I'm brand new to python and pretty new to coding in general, so please bear with me.

I'm trying to execute the for loop:

for numi,i in enumerate(v1):
   for numj,j in enumerate(v1):
       angle=(np.arccos(np.dot(i,j))/(np.linalg.norm(i)*np.linalg.norm(j))))*180/(np.pi)
       print(angle)

but I want to add a condition where the loop skips over any value or i or j that matches any element of two different arrays,

ala=[i for i,x in enumerate(resname) if x=='ALA']
gly=[i for i,x in enumerate(resname) if x=='GLY']

which contain

[0, 9, 14, 45, 56, 72, 87, 101, 102, 126, 145]`

and

[22, 24, 32, 39, 58, 60, 95, 97, 112, 130, 132]`

I tried using a conditional if statement using 'continue', but I don't know the correct syntax to get it to identify when i or j==any element in the array

something like

for numi,i in enumerate(v1):
   if i==ala or i==gly:
       continue
   else:
       for numj,j in enumerate(v1):
           if j==ala or j==gly:
               continue
           else:
               angle=(np.arccos(np.dot(i,j))/(np.linalg.norm(i)*np.linalg.norm(j))))*180/(np.pi)
               print(angle)

except with code that actually works

Aucun commentaire:

Enregistrer un commentaire