Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def num_of_orthogonal(vectors):
  2.     """ this function returns the number of orthogonal vectors pairs from the
  3.    list"""
  4.     orthogonal_pairs = 0
  5.  
  6.     # We'll iterate the vectors in the following form, in order to avoid
  7.     # duplications:
  8.     # if the vectors are A, B, C, D we need to check only the next pairs:
  9.     # AB, AC, AD
  10.     # BC, BD
  11.     # CD
  12.     # So we'll use nested loops but each time the main loop go, the nested loop
  13.     # is quicker.
  14.     # Finally, we'll use inner_product function to check the product.
  15.  
  16.     for i in range(len(vectors) - 1):
  17.         for t in range(i + 1, len(vectors)):
  18.             if inner_product(vectors[i], vectors[t]) is 0:
  19.                 orthogonal_pairs += 1
  20.     return orthogonal_pairs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement