-
-
Save Atlas7/307a5d7551432c95a0ef38e203ea06dd to your computer and use it in GitHub Desktop.
array_broadcast.py
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 | |
import matplotlib.pyplot as plt | |
# Create x and y axis | |
x, y = np.arange(-99, 100), np.arange(-99, 100) | |
# Turn 1D arrays into 2D with array broadcasting | |
distance = np.sqrt(x**2 + y[:, np.newaxis]**2) | |
# print(distance) | |
# Plot it baby oh yeah! | |
plt.pcolor(x, y, distance) | |
plt.colorbar() | |
plt.axis(x.min(), x.max(), y.min(), y.max()) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment