TensorTonic
Problems
Rank Transform
Feature Engineering
Easy

Rank transformation replaces each value with its one-based position in ascending order. The smallest value receives rank 1. When equal values occupy several positions, assign all of them the average of those positions.

Return ranks in the original input order so each output position corresponds to the value at the same input position.

Loading visualization...

Examples

Input: values = [10, 30, 20]

Output: [1.0, 3.0, 2.0]

Explanation: Sorting gives 10, 20, 30, whose ranks are 1, 2, and 3 before restoring the original order.

Input: values = [1, 2, 2, 3]

Output: [1.0, 2.5, 2.5, 4.0]

Hint 1

Sort input indices by their corresponding values.

Hint 2

Process equal values as one consecutive group in the sorted index list.

Requirements

  • Assign one-based ranks in ascending value order.
  • Give tied values the average of the positions they occupy.
  • Return ranks aligned with the original input order.
  • Return a list of floats.

Constraints

  • values is nonempty.
  • Values may be negative, zero, repeated, or positive.
  • Time limit: 300 ms.
Try Similar Problems
Polynomial FeaturesEasyBinningEasyLog Transform Features in PythonEasyImplement z-Score StandardizationEasyPercentiles / QuantilesEasyInteraction FeaturesEasyLag FeaturesEasyFrequency EncodingEasyMissing Value ImputationEasyAngle FeaturesEasyBag of WordsEasyFeature ScalingEasy
Scratchpad

Accepts: array

You must run your code first.
Rank Transform

Rank Transform

Feature Engineering
Easy

Rank transformation replaces each value with its one-based position in ascending order. The smallest value receives rank 1. When equal values occupy several positions, assign all of them the average of those positions.

Return ranks in the original input order so each output position corresponds to the value at the same input position.

Loading visualization...

Examples

Input: values = [10, 30, 20]

Output: [1.0, 3.0, 2.0]

Explanation: Sorting gives 10, 20, 30, whose ranks are 1, 2, and 3 before restoring the original order.

Input: values = [1, 2, 2, 3]

Output: [1.0, 2.5, 2.5, 4.0]

Hint 1

Sort input indices by their corresponding values.

Hint 2

Process equal values as one consecutive group in the sorted index list.

Requirements

  • Assign one-based ranks in ascending value order.
  • Give tied values the average of the positions they occupy.
  • Return ranks aligned with the original input order.
  • Return a list of floats.

Constraints

  • values is nonempty.
  • Values may be negative, zero, repeated, or positive.
  • Time limit: 300 ms.
Try Similar Problems
Polynomial FeaturesEasyBinningEasyLog Transform Features in PythonEasyImplement z-Score StandardizationEasyPercentiles / QuantilesEasyInteraction FeaturesEasyLag FeaturesEasyFrequency EncodingEasyMissing Value ImputationEasyAngle FeaturesEasyBag of WordsEasyFeature ScalingEasy
Scratchpad

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1