Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-286

Projection Onto Nonnegative Orthant

Problem

The Euclidean projection onto the nonnegative orthant replaces negative coordinates with zero.

Given the point, return the projected point.

Hint

Take the positive part of every coordinate.

Test cases

case 1
in: [[1,-2,3]]
expected: [1,0,3]
case 2
in: [[-1,-1]]
expected: [0,0]
case 3
in: [[0,4]]
expected: [0,4]
Starter codePython
def projection_onto_nonnegative_orthant(x):
    # Your code here
    pass

3 test cases · run your code against them in the editor