def calculate_normals(vertices):
    """Return Nx3 normal array from Nx3 vertex array."""
    verts = np.array(vertices, dtype=float)
    normals = np.zeros_like(verts)
    for start, end in pairwise(np.arange(0, verts.shape[0] + 1, 3)):
        vecs = np.vstack((verts[start + 1] - verts[start], verts[start + 2] - verts[start]))  # Get triangle of vertices and calculate 2-1 and 3-1
        vecs /= np.linalg.norm(vecs, axis=1, keepdims=True)  # normalize vectors
        normal = np.cross(*vecs)  # normal is the cross products of vectors.
        normals[start:end, :] = normal / np.linalg.norm(normal)
    return normals
Return Nx3 normal array from Nx3 vertex array.