Clamp a Matrix
Clamp every element of a matrix to a specified min and max range. Supports custom dimensions, CSV/JSON output, and highlights clamped values.
About
Clamping a matrix restricts every element aij to a closed interval [L, U]. Values below L are raised to L. Values above U are reduced to U. This operation is non-negotiable in numerical computing: unclamped data causes overflow in fixed-point arithmetic, color channel corruption in image processing, and divergence in iterative solvers. The tool applies the standard element-wise clamp function across matrices up to 20×20 and visually marks every cell that was modified, so you can audit exactly where your raw data exceeded bounds.
A common failure mode: confusing clamp with normalization. Normalization rescales the entire distribution; clamping truncates outliers and destroys information beyond the bounds. If your downstream pipeline assumes a Gaussian distribution, clamping tails will bias your statistics. Use this tool when hard saturation is the correct behavior - sensor limits, pixel intensities in [0, 255], or weight constraints in neural network quantization. The tool assumes real-valued entries and does not handle complex numbers.
Formulas
The element-wise clamp operation on a matrix A of dimension m×n with lower bound L and upper bound U is defined as:
Applied element-wise: the result matrix B has identical dimensions to A, where bij = clamp(aij, L, U) for all 1 ≤ i ≤ m and 1 ≤ j ≤ n.
Where: aij = element at row i, column j of the input matrix. L = lower bound (minimum allowed value). U = upper bound (maximum allowed value). Constraint: L ≤ U must hold. If violated, the tool rejects the input.
Reference Data
| Domain | Typical Clamp Range | Reason |
|---|---|---|
| 8-bit Image (per channel) | [0, 255] | Unsigned byte overflow prevention |
| 16-bit Image (per channel) | [0, 65535] | HDR sensor saturation limit |
| Normalized Float Image | [0.0, 1.0] | GPU shader precision range |
| Audio Sample (16-bit PCM) | [−32768, 32767] | Signed integer clipping guard |
| Audio Sample (float) | [−1.0, 1.0] | DAC full-scale normalization |
| Neural Net Weights (INT8 quantization) | [−128, 127] | Post-training quantization range |
| Gradient Clipping (deep learning) | [−1.0, 1.0] | Prevents exploding gradients |
| PID Controller Output | [0, 100] % | Actuator physical saturation |
| GPS Latitude | [−90, 90] ° | Geographic coordinate validity |
| GPS Longitude | [−180, 180] ° | Geographic coordinate validity |
| Probability | [0, 1] | Axiom of probability theory |
| CSS Opacity | [0, 1] | Render engine constraint |
| Percentage | [0, 100] | Logical bound for ratios |
| Servo Motor Angle | [0, 180] ° | Physical rotation limit |
| Temperature Sensor (thermocouple K) | [−200, 1372] °C | Type K operating range |
| Battery SoC | [0, 100] % | State-of-charge physical bound |
| dB SPL (human hearing) | [0, 194] dB | Threshold of hearing to theoretical max in air |
| RGB Hex Channel | [0x00, 0xFF] | Hexadecimal byte constraint |
| Sigmoid Activation Output | (0, 1) | Asymptotic bounds of logistic function |
| Tanh Activation Output | (−1, 1) | Hyperbolic tangent range |
Frequently Asked Questions
np.clip() or equivalent.