-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from JvgRansika/dot-multiplication
added dot()
- Loading branch information
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .addition import addition | ||
from .addition import addition | ||
from .multiplication import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def multiply_with_scalar(v, s): | ||
""" | ||
:param v: vector | ||
:param s: scalar | ||
:return: tuple with components of result vector | ||
""" | ||
return tuple(x * s for x in v.components) | ||
|
||
def dot_multiplication_with_vector(v1, v2): | ||
""" | ||
:param v1: | ||
:param v2: | ||
:return: a number | ||
""" | ||
if v1.get_dimension() != v2.get_dimension(): | ||
raise Exception("both vector must be in same dimension for dot product") | ||
|
||
return sum(x*y for x,y in zip(v1.components, v2.components)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters