Normalize one 3D vector or every row in a batch to unit length:
v=∥v∥2vHere, ∥v∥2 is the Euclidean norm. A zero vector has no direction, so return a zero row for it. Preserve the input shape and return a floating-point NumPy array.
Input: v = [3, 4, 0]
Output: [0.6, 0.8, 0]
Explanation: The vector norm is 5, so dividing each coordinate by 5 produces a unit vector.
Input: v = [[0, 0, 0], [1, 2, 2]]
Output: [[0, 0, 0], [0.333333, 0.666667, 0.666667]]
Compute norms with keepdims=True so they broadcast over coordinates.
Use np.divide(values, norms, out=np.zeros_like(values), where=norms != 0).
Sign in to take notes on this problem
Accepts: array
Normalize one 3D vector or every row in a batch to unit length:
v=∥v∥2vHere, ∥v∥2 is the Euclidean norm. A zero vector has no direction, so return a zero row for it. Preserve the input shape and return a floating-point NumPy array.
Input: v = [3, 4, 0]
Output: [0.6, 0.8, 0]
Explanation: The vector norm is 5, so dividing each coordinate by 5 produces a unit vector.
Input: v = [[0, 0, 0], [1, 2, 2]]
Output: [[0, 0, 0], [0.333333, 0.666667, 0.666667]]
Compute norms with keepdims=True so they broadcast over coordinates.
Use np.divide(values, norms, out=np.zeros_like(values), where=norms != 0).
Sign in to take notes on this problem
Accepts: array