When or why should I use numpy.meshgrid (Ny,Nx) arrays instead of two (1,Nx) and (Ny,1) arrays?
I have been extensively using numpy arrays recently, and have discovered that what I used to do with meshgrids could be done with smaller 1D arrays:
import numpy as np
def myfun(x,y):
return np.sin(x**2 + y**2) / (x**2 + y**2)
# create 2 arrays, each 1D but not on the same dimension
x = np.array([1,2,3,4,5]).reshape(1,-1)
y = np.array([6,7,8]).reshape(-1,1)
# make some computation
z = myfun(x,y)
# same with full 2D arrays
xx, yy = np.meshgrid(x,y,indexing='xy')
zz = myfun(xx,yy)
if (zz == z).all():
print("They are the same array!")
So when should I use the full (Ny,Nx) xx and yy instead of the 1D versions?