RuntimeWarning: invalid value encountered in divide vertex_normals /= np.linalg.norm(vertex_normals, axis=1).reshape((-1, 1))
时间: 2024-05-20 14:17:11 浏览: 111
This warning occurs when there is a division by zero or when the result of a division is not a number (NaN). In this case, it is likely that the norm of some vertex normals is zero, causing a division by zero.
To fix this warning, you can check if the norm of each vertex normal is zero and set the corresponding values to a default value (e.g. [0,0,1] for a unit vector pointing in the z direction). Here is an example code snippet:
norms = np.linalg.norm(vertex_normals, axis=1)
zero_norms = np.where(norms == 0)[0]
default_normal = np.array([0,0,1])
if zero_norms.size > 0:
vertex_normals[zero_norms] = default_normal
norms[zero_norms] = 1
vertex_normals /= norms.reshape((-1, 1))
This code first computes the norms of the vertex normals, then checks if any of them are zero. If so, it sets the corresponding vertex normals to the default normal vector and sets their norms to 1 (to avoid division by zero). Finally, it divides all the vertex normals by their norms.
阅读全文