【Functions of Numpy】np.meshgri(x,y)

officia doc:

https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.htmlicon-default.png?t=M85Bhttps://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html

Return coordinate matrices from coordinate vectors 

 example:

import numpy as np

nx,ny = (3,2)
x = np.linspace(0,1,nx)
y = np.linspace(0,1,ny)

xv,yv = np.meshgrid(x,y)
print("x:\n",x)
print("\ny:\n",y)
print("\nxv:\n",xv)
print("\nyv:\n",yv)

import matplotlib.pyplot as plt

plt.plot(xv,yv,"*")
plt.grid(True)
plt.show()

result:

x:
 [0.  0.5 1. ]

y:
 [0. 1.]

xv:
 [[0.  0.5 1. ]
 [0.  0.5 1. ]]

yv:
 [[0. 0. 0.]
 [1. 1. 1.]]

 fig:

 【Functions of Numpy】np.meshgri(x,y)_第1张图片

 

你可能感兴趣的:(Python,numpy,python,机器学习)