normalize method
Normalizes the matrix by dividing each element by the maximum element value.
Returns a new normalized matrix.
Example:
var matrix = Matrix([[1, 2], [3, 4]]);
var result = matrix.normalize();
print(result);
// Output:
// 0.25 0.5
// 0.75 1.0
Implementation
Matrix normalize([Norm? normType]) {
if (_data.isEmpty) {
throw Exception("Matrix is empty");
}
if (normType != null) {
return this / norm(normType);
}
dynamic maxValue = max();
if (maxValue == Complex(0)) {
throw Exception("Matrix is filled with zeros, cannot normalize");
}
return this / maxValue;
}