TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Compute 3D Vector Norm

3D Geometry
Easy

Compute the Euclidean length of one 3D vector or a batch of 3D vectors:

∥v∥2=x2+y2+z2\lVert\mathbf{v}\rVert_2=\sqrt{x^2+y^2+z^2}∥v∥2​=x2+y2+z2​

Here, xxx, yyy, and zzz are the three vector components. A single input has shape (3,) and returns a Python float. A batch has shape (N, 3) and returns a NumPy array containing one norm per row.

Loading visualization...

Examples

Input: v = [3, 4, 12]

Output: 13

Explanation: The squared components sum to 169, whose square root is 13.

Input: v = [[1, 0, 0], [0, 3, 4]]

Output: [1, 5]

Hint 1

Use np.sum(values ** 2, axis=-1) for both accepted shapes.

Hint 2

Convert a zero-dimensional result with float(norms); otherwise return the array.

Requirements

  • Compute the sum of squared components along the final axis
  • Return a Python float for one vector
  • Return a one-dimensional NumPy array for a batch
  • Do not loop over batch rows

Constraints

  • Input shape is (3,) or (N, 3)
  • N <= 100000
  • Use NumPy only
Try Similar Problems
Normalize 3dAngle Between 3dEuclidean DistanceDot ProductManhattan Distance

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.
PrevNext

Compute 3D Vector Norm

3D Geometry
Easy

Compute the Euclidean length of one 3D vector or a batch of 3D vectors:

∥v∥2=x2+y2+z2\lVert\mathbf{v}\rVert_2=\sqrt{x^2+y^2+z^2}∥v∥2​=x2+y2+z2​

Here, xxx, yyy, and zzz are the three vector components. A single input has shape (3,) and returns a Python float. A batch has shape (N, 3) and returns a NumPy array containing one norm per row.

Loading visualization...

Examples

Input: v = [3, 4, 12]

Output: 13

Explanation: The squared components sum to 169, whose square root is 13.

Input: v = [[1, 0, 0], [0, 3, 4]]

Output: [1, 5]

Hint 1

Use np.sum(values ** 2, axis=-1) for both accepted shapes.

Hint 2

Convert a zero-dimensional result with float(norms); otherwise return the array.

Requirements

  • Compute the sum of squared components along the final axis
  • Return a Python float for one vector
  • Return a one-dimensional NumPy array for a batch
  • Do not loop over batch rows

Constraints

  • Input shape is (3,) or (N, 3)
  • N <= 100000
  • Use NumPy only
Try Similar Problems
Normalize 3dAngle Between 3dEuclidean DistanceDot ProductManhattan Distance

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.