Created
May 16, 2018 11:14
-
-
Save serihiro/8ecfde5cb86906868110577407815739 to your computer and use it in GitHub Desktop.
linear transformation
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 | |
test_a = np.array([ | |
[1, 2, 3, 4, 5, 6], | |
[7, 8, 9, 10, 11, 12], | |
[13, 14, 15, 16, 17, 18], | |
[19, 20, 21, 22, 23, 24], | |
[25, 26, 27, 28, 29, 30], | |
[31, 32, 33, 34, 35, 36], | |
]) | |
test_b = np.array([37, 38, 39, 40, 41, 42]) | |
expect = np.dot(test_a.T, test_b) | |
test_a_0 = test_a[0:3, 0:3] | |
test_a_1 = test_a[0:3, 3:6] | |
test_a_2 = test_a[3:6, 0:3] | |
test_a_3 = test_a[3:6, 3:6] | |
test_b_0 = test_b[0:3] | |
test_b_1 = test_b[3:6] | |
actual = np.vstack( | |
( | |
np.dot(test_a_0.T, test_b_0) + np.dot(test_a_2.T, test_b_1), | |
np.dot(test_a_1.T, test_b_0) + np.dot(test_a_3.T, test_b_1) | |
) | |
).reshape(-1) | |
print(actual) | |
print(expect) | |
print(np.array_equal(expect, actual)) # => True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment