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

Streaming Min-Max Normalization

Feature EngineeringData Processing
Medium

Normalize a sequence of batches while maintaining running per-feature extrema. Initialize each running minimum to +∞+\infty+∞ and each running maximum to −∞-\infty−∞. For every incoming batch, update both arrays before normalizing that batch:

xij′=xij−mjmax⁡(Mj−mj,ε)x'_{ij} = \frac{x_{ij}-m_j}{\max(M_j-m_j,\varepsilon)}xij′​=max(Mj​−mj​,ε)xij​−mj​​

Here, mjm_jmj​ and MjM_jMj​ are the updated running minimum and maximum for feature jjj, and ε\varepsilonε is eps. Return normalized_batches as a list of NumPy arrays and the final min and max arrays in a dictionary.

Loading visualization...

Examples

Input: D = 2, batches = [[[1, 3], [2, 1]]]

Output: {"normalized_batches": [[[0.0, 1.0], [1.0, 0.0]]], "min": [1.0, 1.0], "max": [2.0, 3.0]}

Explanation: The first batch establishes both feature ranges before it is normalized.

Input: D = 1, batches = [[[5], [3]]]

Output: {"normalized_batches": [[[1.0], [0.0]]], "min": [3.0], "max": [5.0]}

Hint 1

Update state with np.minimum, np.maximum, np.min, and np.max.

Hint 2

Use np.maximum(running_max - running_min, eps) as the denominator.

Requirements

  • Initialize running minima and maxima with positive and negative infinity
  • Update running state before normalizing each batch
  • Protect constant feature ranges with eps
  • Return exactly normalized_batches, min, and max in a dictionary with NumPy array values

Constraints

  • D is a positive integer
  • batches is a nonempty list of nonempty two-dimensional arrays with D columns
  • eps is positive
  • Use NumPy only
Try Similar Problems
Minmax NormalizationOne Hot EncodingMin Max ScalingZscore StandardizationRobust Scaling

Sign in to take notes on this problem

Case 1
Case 2

Accepts: number

Accepts: array

You must run your code first.
PrevNext

Streaming Min-Max Normalization

Feature EngineeringData Processing
Medium

Normalize a sequence of batches while maintaining running per-feature extrema. Initialize each running minimum to +∞+\infty+∞ and each running maximum to −∞-\infty−∞. For every incoming batch, update both arrays before normalizing that batch:

xij′=xij−mjmax⁡(Mj−mj,ε)x'_{ij} = \frac{x_{ij}-m_j}{\max(M_j-m_j,\varepsilon)}xij′​=max(Mj​−mj​,ε)xij​−mj​​

Here, mjm_jmj​ and MjM_jMj​ are the updated running minimum and maximum for feature jjj, and ε\varepsilonε is eps. Return normalized_batches as a list of NumPy arrays and the final min and max arrays in a dictionary.

Loading visualization...

Examples

Input: D = 2, batches = [[[1, 3], [2, 1]]]

Output: {"normalized_batches": [[[0.0, 1.0], [1.0, 0.0]]], "min": [1.0, 1.0], "max": [2.0, 3.0]}

Explanation: The first batch establishes both feature ranges before it is normalized.

Input: D = 1, batches = [[[5], [3]]]

Output: {"normalized_batches": [[[1.0], [0.0]]], "min": [3.0], "max": [5.0]}

Hint 1

Update state with np.minimum, np.maximum, np.min, and np.max.

Hint 2

Use np.maximum(running_max - running_min, eps) as the denominator.

Requirements

  • Initialize running minima and maxima with positive and negative infinity
  • Update running state before normalizing each batch
  • Protect constant feature ranges with eps
  • Return exactly normalized_batches, min, and max in a dictionary with NumPy array values

Constraints

  • D is a positive integer
  • batches is a nonempty list of nonempty two-dimensional arrays with D columns
  • eps is positive
  • Use NumPy only
Try Similar Problems
Minmax NormalizationOne Hot EncodingMin Max ScalingZscore StandardizationRobust Scaling

Sign in to take notes on this problem

Case 1
Case 2

Accepts: number

Accepts: array

You must run your code first.