Qu

min

Builtin index · Core maths

max(x, [on_invalid=]) or max(a, b)

Input: x, on_invalid · Output: no output

What it is

One argument reduces x (a scalar, Vec, or Mat/Signal) to its largest/smallest element, a scalar Num, and accepts on_invalid= ("propagate"/"ignore"/"error", see this section's intro). Two arguments a, b (matching or broadcastable shapes) instead compare elementwise and keep the larger/smaller of each pair — the "clip" idiom, e.g. max(x, 0); on_invalid= does not apply to this two-argument form. In the one-argument form on a Mat, the optional axis= keyword (0 or 1) reduces along just that dimension instead, returning a length-cols/rows Vec rather than a single scalar.

Overloads

x can be scalar, Vec, Mat, Signal, or Num; a can be scalar, Vec, Mat, Signal, or Num.

2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.

CodeInputOutputDescription
result = min(x)
x scalar, Vec, Mat, Signal, or Numnot documented yet
x scalar, Vec, Mat, or Signala scalar, Vec, or Mat/Signal, flattened
Smallest element of x (a scalar, Vec, or Mat/Signal, flattened) — a single scalar Num.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

print(min([1, 5, 3]))      # 1 -- one-argument reduction

print(min([1, 5, 3], 4))   # [1, 4, 3] -- two-argument elementwise clip

output
1
[1, 4, 3]

from core-math

signal = sin(2 * pi * 5 * t)
print("goes from {min(signal):.2f} to {max(signal):.2f}")
output
goes from -1.00 to 1.00

from start-here

m = randn(10, 10, seed = 4)
heatmap(m, colormap="viridis")
colorbar
title("Random field")
print("value range: [" + str(min(m)) + ", " + str(max(m)) + "]")
output
value range: [-2.270955, 2.7556]
0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 0 1 2 3 4 5 x=0.12, y=1 x=0.36, y=0 x=0.6, y=0 x=0.84, y=0 x=1.08, y=0 x=1.32, y=1 x=1.56, y=0 x=1.8, y=1 x=2.04, y=0 x=2.28, y=0 x=2.52, y=0 x=2.76, y=0 x=3, y=1 x=3.24, y=0 x=3.48, y=1 x=3.72, y=0 x=3.96, y=0 x=4.2, y=0 x=4.44, y=0 x=4.68, y=1 0.302 0.302 -2.271 -2.271 0.21 0.21 -0.674 -0.674 -0.388 -0.388 -1.967 -1.967 0.801 0.801 -2.074 -2.074 0.57 0.57 0.164 0.164 -0.939 -0.939 -1.956 -1.956 0.864 0.864 -1.204 -1.204 0.152 0.152 0.238 0.238 -1.99 -1.99 1.128 1.128 -1.676 -1.676 1.75 1.75 0.907 0.907 -0.406 -0.406 1.146 1.146 0.706 0.706 -2.005 -2.005 0.42 0.42 -0.78 -0.78 -0.885 -0.885 0.386 0.386 1.542 1.542 0.526 0.526 $9\times10^{-4}$ 9×10−4 1.113 1.113 -0.142 -0.142 0.83 0.83 1.226 1.226 -0.987 -0.987 1.79 1.79 -2.247 -2.247 -0.425 -0.425 0.304 0.304 0.834 0.834 0.144 0.144 -0.664 -0.664 -0.404 -0.404 0.091 0.091 0.751 0.751 1.335 1.335 0.67 0.67 -0.005 -0.005 -0.819 -0.819 -1.183 -1.183 -1.224 -1.224 -1.306 -1.306 0.993 0.993 -0.278 -0.278 1.171 1.171 0.469 0.469 1.072 1.072 -1.095 -1.095 0.521 0.521 1.397 1.397 -0.292 -0.292 1.682 1.682 -0.281 -0.281 1.3 1.3 -0.484 -0.484 1.198 1.198 0.819 0.819 -0.644 -0.644 -0.528 -0.528 -0.404 -0.404 0.44 0.44 -1.584 -1.584 -0.873 -0.873 -0.55 -0.55 1.347 1.347 -0.657 -0.657 -0.588 -0.588 -2.034 -2.034 0.136 0.136 0.091 0.091 0.565 0.565 -0.569 -0.569 -0.532 -0.532 0.649 0.649 -0.159 -0.159 0.838 0.838 0.081 0.081 0.532 0.532 -1.335 -1.335 -0.046 -0.046 -1.818 -1.818 -0.219 -0.219 2.756 2.756 0.385 0.385 0.101 0.101 1.32 1.32 -0.146 -0.146 0.809 0.809 Random field -1.0 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1.0 0 1 2 3 4 5 x=0, y=0 x=1.8, y=0.063 x=1.2, y=0.126 x=3.5, y=0.188 x=3, y=0.249 x=4.8, y=0.31 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0 10 20 30 40

from plotting

fs = 1000
tone = sine(50, fs, 20)
bits = sigma_delta(tone)            # 1-bit noise-shaping quantizer

print("sigma_delta output range: [{min(bits)}, {max(bits)}]")

s = signal(0 to 9, 10)
trimmed = signal_slice_time(s, 0.2, 0.6)   # same operation `cut` is the friendlier name for

print("signal_slice_time(0.2, 0.6) -> {trimmed}")
output
sigma_delta output range: [-1, 1]
signal_slice_time(0.2, 0.6) -> signal(Fs=10) [2, 3, 4, 5, 6]

from signal-processing

CodeInputOutputDescription
result = min(a, b)
a scalar, Vec, Mat, Signal, or NumOne argument reduces x (a scalar, Vec, or Mat/Signal) to its largest/smallest element, a scalar Num, and accepts on_invalid= ("propagate"/"ignore"/"error", see this section's intro).
b —Two arguments a, b (matching or broadcastable shapes) instead compare elementwise and keep the larger/smaller of each pair — the "clip" idiom, e.g.
b —matching or broadcastable shapes
Elementwise min of a and b (matching or broadcastable shapes) — the same "clip" idiom as max, from the other side.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

print(min([1, 5, 3]))      # 1 -- one-argument reduction

print(min([1, 5, 3], 4))   # [1, 4, 3] -- two-argument elementwise clip

output
1
[1, 4, 3]

from core-math

clipped = min(max(x, -1), 1)   # same as clip(x, -1, 1)

from fundamentals

See also

max — documented in the same entry.