Qu

prod

Builtin index · Core maths

result = prod(x)

Input: x · Output: result

What it is

Product of every element of x — a scalar, Vec, or Mat/Signal, real only (unlike sum, does not accept a CVec/CMat). A boolean mask counts as 0/1, like every numeric reduction. With no other argument, reduces to one scalar Num. On a Mat, the optional axis= keyword (0 or 1) reduces along just that dimension instead, returning a Vec of length cols/rows. prod does NOT accept on_invalid= — that keyword was added to sum and the other nine reductions listed in this section's intro, not to prod.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = prod(x)
x scalar, Vec, Mat, Signal, CVec, CMat, boolean, or Numnot documented yet
result scalar, Num, or Vec
Returns a scalar Num, or that Vec under axis=.

Examples

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

v = [5.0, 3.0, 8.0, 1.0, 9.0]
print("prod={prod(v)}")
print("argmedian={argmedian(v)}  argquantile(0.9)={argquantile(v, 0.9)}  argmean={argmean(v)}")
print("clamp={clamp([-5, 0, 5, 10], 0, 5)}")
print("var={var(v)}  std^2={std(v)^2}")
print("lse={lse(v)}")
output
prod=1080
argmedian=0  argquantile(0.9)=4  argmean=0
clamp=[0, 0, 5, 5]
var=11.2  std^2=11.2
lse=9.328591

from core-math