Given 3D vector(s) v, return the unit vector(s). Handle zero vectors by returning a zero vector (no division by zero).
Unit Vector Formula:
v^=∥v∥vFor zero vectors (∥v∥=0), return unchanged (all zeros)
Input: v = [3, 4, 0]
Output: [0.6, 0.8, 0.0]
Input: v = [[0, 0, 0], [1, 2, 2]]
Output: [[0, 0, 0], [0.333, 0.667, 0.667]] (approx)
Compute norms and check if norm >10-10 before dividing to avoid division by zero.
For batch, use keepdims=True when computing norms to maintain shape for broadcasting.
np.ndarray of dtype floatSign in to take notes on this problem
Accepts: array
Given 3D vector(s) v, return the unit vector(s). Handle zero vectors by returning a zero vector (no division by zero).
Unit Vector Formula:
v^=∥v∥vFor zero vectors (∥v∥=0), return unchanged (all zeros)
Input: v = [3, 4, 0]
Output: [0.6, 0.8, 0.0]
Input: v = [[0, 0, 0], [1, 2, 2]]
Output: [[0, 0, 0], [0.333, 0.667, 0.667]] (approx)
Compute norms and check if norm >10-10 before dividing to avoid division by zero.
For batch, use keepdims=True when computing norms to maintain shape for broadcasting.
np.ndarray of dtype floatSign in to take notes on this problem
Accepts: array