Create a gist now

Instantly share code, notes, and snippets.

Embed
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