NumPy Meshgrid 3D

the
NumPy.meshgrid()
Function in Python 
Implement the
NumPy.meshgrid()
Function to Create a 3Dimensional Meshgrid in Python
We can define a mesh grid in Python as a function capable of generating a rectangular grid when given two onedimensional arrays. It is a useful function and is inspired by MATLAB
.
In Python, the ability to create a mesh grid function comes with using the NumPy
library. This tutorial discusses how to create a 3dimensional mesh grid with the help of NumPy
in Python.
the NumPy.meshgrid()
Function in Python
The NumPy.meshgrid()
function takes in the coordinate vectors and returns a coordinate matrix with their help.
However, this function does not just work for generating twodimensional arrays. Due to the regular updates, the NumPy.meshgrid()
function can now take in N
onedimensional arrays and delivers matrices of the size ND
.
Implement the NumPy.meshgrid()
Function to Create a 3Dimensional Meshgrid in Python
The NumPy.meshgrid()
function can directly be utilized after importing the NumPy
library to the Python code.
The following code uses the NumPy.meshgrid()
function to create a threedimensional mesh grid in Python.
import numpy as np
xa = np.linspace(0., 1., 2)
ya = np.linspace(2., 2., 2)
za = np.linspace(3., 5., 2)
out = np.meshgrid(xa, ya, za)
print(out)
The above code provides the following output.
[array([[[0., 0.],
[1., 1.]],
[[0., 0.],
[1., 1.]]]), array([[[2., 2.],
[2., 2.]],
[[2., 2.],
[2., 2.]]]), array([[[3., 5.],
[3., 5.]],
[[3., 5.],
[3., 5.]]])]