Gradient Orientation

~8 mincode completion

Implement gradient_orientation(Ix, Iy) returning atan2(Iy, Ix) element-wise, in radians.

Examples

Along +x the angle is 0

Input
gradient_orientation(1, 0)
Output
0

Along +y the angle is pi/2

Input
gradient_orientation(0, 1)
Output
1.5708

Along -x the angle is pi

Input
gradient_orientation(-1, 0)
Output
3.14159

Hints

Hint 1

Convert the input with before doing elementwise work.

Hint 2

Watch for this: called atan2 with ix first.

Requirements

  • Return array of the same shape

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~8 min

8 employers weight this skill

4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 93.

Python
import numpy as np


def gradient_orientation(Ix, Iy):
    """
    Angle of the image gradient, in radians.

    Args:
        Ix, Iy: arrays of the same shape

    Returns:
        array of the same shape
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.