Binarize

EasyMachine LearningArray

Description

Given an array and a threshold, return a binary array with 1 where the value is strictly greater than the threshold and 0 otherwise.

Examples

Input:[1,2,3,4], 2
Output:[0,0,1,1]
Explanation:

Every value above the threshold maps to one and everything at or below it maps to zero.

Input:[5,0,3], 0
Output:[1,0,1]
Explanation:

Every value above the threshold maps to one and everything at or below it maps to zero.

Input:[-1,1], 0
Output:[0,1]
Explanation:

Every value above the threshold maps to one and everything at or below it maps to zero.

Constraints

  • 1 ≤ length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.