Created
March 8, 2018 07:05
-
-
Save izmailoff/9394006d2238a44131fc3b1f8b6bef79 to your computer and use it in GitHub Desktop.
Change of basis for vectors
This file contains hidden or 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
import numpy as np | |
def change_basis(v, dims): | |
""" | |
:param v: vector of any dimension | |
:param dims: basis of new dimension matching dimensions of v | |
:return: the same vector v in new coordinate space | |
""" | |
return [np.dot(v, x) / np.dot(x, x) for x in dims] | |
change_basis([5, -1], [[1, 1], [1, -1]]) | |
change_basis([10, -5], [[3, 4], [4, -3]]) | |
change_basis([2, 2], [[-3, 1], [1, 3]]) | |
change_basis([1, 1, 1], [[2, 1, 0], [1, -2, -1], [-1, 2, -5]]) | |
change_basis([1, 1, 2, 3], [[1, 0, 0, 0], [0, 2, -1, 0], [0, 1, 2, 0], [0, 0, 0, 3]]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment