Skip to content

Instantly share code, notes, and snippets.

@Atlas7
Created May 19, 2017 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atlas7/307a5d7551432c95a0ef38e203ea06dd to your computer and use it in GitHub Desktop.
Save Atlas7/307a5d7551432c95a0ef38e203ea06dd to your computer and use it in GitHub Desktop.
array_broadcast.py
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