normalize — Normalize data by centering and scaling along a dimension.
normalize(A) returns z-scores along the first nonsingleton dimension. Select another method, operating dimension, or explicit center and scale with additional arguments.
Syntax
N = normalize(A)
N = normalize(A, dim)
N = normalize(A, method)
N = normalize(A, dim, method)
N = normalize(A, method, methodtype)
N = normalize(A, dim, method, methodtype)All supported normalize forms
N = normalize(A)
N = normalize(A, dim)
N = normalize(A, method)
N = normalize(A, dim, method)
N = normalize(A, method, methodtype)
N = normalize(A, dim, method, methodtype)
N = normalize(A, "center", centertype, "scale", scaletype)
N = normalize(A, dim, "center", centertype, "scale", scaletype)
[N, C, S] = normalize(___)Inputs
A- Type
Any- Required
- Yes
- Description
- Floating input data; native integer and logical data are gated RunMat extensions.
dim- Type
NumericArray- Required
- No
- Description
- Dimension to operate along.
method- Type
StringScalar- Required
- No
- Default
"zscore"- Description
- Normalization method: zscore, norm, scale, range, center, or medianiqr.
methodtype- Type
Any- Required
- No
- Description
- Method subtype or explicit center/scale/range parameter.
center_keyword- Type
StringScalar- Required
- Yes
- Default
"center"- Description
- Literal center method selector.
centertype- Type
Any- Required
- Yes
- Description
- Centering mode or explicit center values.
scale_keyword- Type
StringScalar- Required
- Yes
- Default
"scale"- Description
- Literal scale method selector.
scaletype- Type
Any- Required
- Yes
- Description
- Scaling mode or explicit scale values.
Returns
N- Type
NumericArray- Description
- Normalized data.
C- Type
NumericArray- Description
- Centering values.
S- Type
NumericArray- Description
- Scale values.
Returned values from normalize depend on how many outputs the caller requests.
Errors
RunMat:normalize:InvalidArgument- When
- Inputs, dimension, method, method type, or name-value options are malformed.
- Message
normalize: invalid argument
RunMat:normalize:Internal- When
- Internal tensor conversion or allocation fails.
- Message
normalize: internal error
Methods and outputs
Default z-score normalization subtracts the mean and divides by the sample standard deviation, omitting NaN observations when calculating the parameters and retaining their positions in N. The optional positive dim selects the operating dimension.
Methods include "zscore", robust z-score, "norm" with optional positive order, "scale", "range", "center", and "medianiqr". Combined "center", centertype, "scale", scaletype forms also accept explicit numeric parameter arrays with compatible implicit expansion.
[N,C,S] = normalize(...) returns the normalized array, center, and scale parameters for reuse. Parameter shapes depend on the method and any explicit parameters.
Classes and exactness
Single input produces single N, C, and S; double input produces double outputs. Complex floating-point input is supported except for range normalization. Integer and logical input are separately gated RunMat extensions and produce double outputs.
Admitted integer input data and numeric parameters must be exactly representable at the binary64 normalization boundary. Values that would lose integer precision are rejected rather than rounded.
Resident arrays
Floating resident input currently uses class-preserving host calculation. Requested numeric outputs are restored through the input's exact provider owner when it can represent their class. An incompatible automatic owner may leave the correct-class result on the host; explicit gpuArray intent errors if residency cannot be preserved.
Automatic resident controls may be gathered. Explicit resident control or parameter values are a gated RunMat extension and do not determine output residency. This is a host-materialization boundary, not a resident normalization kernel.
Table and timetable DataVariables and ReplaceValues forms are not yet supported for array input.
Examples
Default z-score normalization
N = normalize([1; 2; 3]); disp(N);Expected output:
[-1; 0; 1]Normalize by Euclidean norm
N = normalize([3; 4], "norm"); disp(N);Expected output:
[0.6; 0.8]Using normalize with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how normalize changes the result.
Run a small normalize example, explain the result, then change one input and compare the output.
FAQ
What does normalize do by default?⌄
It subtracts the mean and divides by the sample standard deviation along the first nonsingleton dimension.
Does single input stay single?⌄
Yes. Single input produces single normalized data and center/scale parameters.
Can normalize operate on gpuArray input?⌄
The current implementation gathers for host calculation and restores supported outputs through the input's provider; it does not execute a resident normalization kernel.
Related Stats functions
Summary
anova1 · binocdf · binscatter · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · ksdensity · kstest · kurtosis · lsline · mad · mode · nanmax · normcdf · norminv · normpdf · onehotdecode · onehotencode · pca · pdf · prctile · qqplot · quantile · refline · rmse · scatterhist · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest · ttest2 · wblinv
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · nlparci · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · gpurng · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Source you can read
Every RunMat function's source is public. Read exactly how normalize is executed, line by line, in Rust.
- View the source for normalize in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.