Given a 3D vector v=(x,y,z), compute its Euclidean norm. You'll write a function that works on single 3D vectors or a batch of 3D vectors with shape (N,3).
Euclidean Norm Formula:
∥v∥=x2+y2+z2Input: v = [3, 4, 12]
Output: 13.0
Input: v = [[1, 0, 0], [0, 3, 4]]
Output: [1.0, 5.0] (shape = (2,))
Use np.asarray() to convert input and check v.ndim to distinguish single vector from batch.
For batch: use axis=1 with np.sum(v**2, axis=1) to compute norm for each vector.
Sign in to take notes on this problem
Accepts: array
Given a 3D vector v=(x,y,z), compute its Euclidean norm. You'll write a function that works on single 3D vectors or a batch of 3D vectors with shape (N,3).
Euclidean Norm Formula:
∥v∥=x2+y2+z2Input: v = [3, 4, 12]
Output: 13.0
Input: v = [[1, 0, 0], [0, 3, 4]]
Output: [1.0, 5.0] (shape = (2,))
Use np.asarray() to convert input and check v.ndim to distinguish single vector from batch.
For batch: use axis=1 with np.sum(v**2, axis=1) to compute norm for each vector.
Sign in to take notes on this problem
Accepts: array