Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def num_of_orthogonal(vectors):
- """ this function returns the number of orthogonal vectors pairs from the
- list"""
- orthogonal_pairs = 0
- # We'll iterate the vectors in the following form, in order to avoid
- # duplications:
- # if the vectors are A, B, C, D we need to check only the next pairs:
- # AB, AC, AD
- # BC, BD
- # CD
- # So we'll use nested loops but each time the main loop go, the nested loop
- # is quicker.
- # Finally, we'll use inner_product function to check the product.
- for i in range(len(vectors) - 1):
- for t in range(i + 1, len(vectors)):
- if inner_product(vectors[i], vectors[t]) is 0:
- orthogonal_pairs += 1
- return orthogonal_pairs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement