def normalize(u):
u = np.asarray(u)<EOL>unorm = np.sqrt(np.sum(u**<NUM_LIT:2>, axis=<NUM_LIT:0>))<EOL>z = np.isclose(unorm, <NUM_LIT:0>)<EOL>c = np.logical_not(z) / (unorm + z)<EOL>return u * c<EOL>
normalize(u) yields a vetor with the same direction as u but unit length, or, if u has zero
length, yields u.