'Calculate normal vectors for each element of a grid in Python

Is there a function to calculate rapidly the normal vectors of each of the meshes of my grid? I'm looking to have vectors of the form n = [nx, ny, nz], for the example below it is easy to calculate it but the Mz will evolve and I have to update the vectors at each step.

import numpy as np
import matplotlib.pyplot as plt

m, n = 21, 21 #n nodes
dx, dy = 21.e-6, 21.e-6 #size x y 
        
x = np.linspace(0, dx, n)
y = np.linspace(0, dy, m)
Mx, My = np.meshgrid(x, y)
Mz = np.zeros((m, n))


#PLOT 
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.plot_wireframe(Mx*1e3, My*1e3, Mz*1e3)

ax.set_xlabel('$X~(mm)$')
ax.set_ylabel('$Y~(mm)$')
ax.set_zlabel('$Z~(mm)$')

plt.show()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source