Skip to content

Commit a17e264

Browse files
committed
Vector product.
1 parent 0f700d1 commit a17e264

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

math_library.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
def scalar_product(vector1, vector2):
22
if len(vector1) != len(vector2):
33
raise ValueError("Vectors must be of the same length")
4-
return sum(x * y for x, y in zip(vector1, vector2))
4+
return sum(x * y for x, y in zip(vector1, vector2))
5+
def vector_product(vector1, vector2):
6+
if len(vector1) != 3 or len(vector2) != 3:
7+
raise ValueError("Both vectors must be of length 3")
8+
return [
9+
vector1[1] * vector2[2] - vector1[2] * vector2[1],
10+
vector1[2] * vector2[0] - vector1[0] * vector2[2],
11+
vector1[0] * vector2[1] - vector1[1] * vector2[0]
12+
]

0 commit comments

Comments
 (0)