min
max(x, [on_invalid=])ormax(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.
| Code | Input | Output | Description |
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
1 [1, 4, 3]
from core-math
signal = sin(2 * pi * 5 * t)
print("goes from {min(signal):.2f} to {max(signal):.2f}")
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)) + "]")
value range: [-2.270955, 2.7556]
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}")
sigma_delta output range: [-1, 1] signal_slice_time(0.2, 0.6) -> signal(Fs=10) [2, 3, 4, 5, 6]
from signal-processing
| Code | Input | Output | Description |
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
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.