Created
November 18, 2016 22:07
-
-
Save PaperclipBadger/7d7632a2d0f0a423529c4d57e5e59c28 to your computer and use it in GitHub Desktop.
A demonstration of NumPy's broadcasting semantics.
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
import numpy as np | |
a = np.array([[1, 1, 1], | |
[2, 2, 2], | |
[3, 3, 3]]) | |
b = np.array([1, 2, 3]) | |
c = np.array([[1], | |
[2], | |
[3]]) | |
print(np.array_equal(a + b, | |
np.array([[2, 3, 4], | |
[3, 4, 5], | |
[4, 5, 6]])) # True | |
print(np.array_equal(a + c, | |
np.array([[2, 2, 2], | |
[4, 4, 4], | |
[6, 6, 6]])) # True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment