Matrix.scalar constructor
Creates a matrix of size
* size
dimension, where all the main
diagonal elements are equal to scalar
, the rest of the elements are 0
import 'package:ml_linalg/matrix.dart';
void main() {
final matrix = Matrix.scalar(3, 5);
print(matrix);
}
The output:
Matrix 5 x 5:
(3.0, 0.0, 0.0, 0.0, 0.0)
(0.0, 3.0, 0.0, 0.0, 0.0)
(0.0, 0.0, 3.0, 0.0, 0.0)
(0.0, 0.0, 0.0, 3.0, 0.0)
(0.0, 0.0, 0.0, 0.0, 3.0)
Implementation
factory Matrix.scalar(
double scalar,
int size, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.scalar(scalar, size);
case DType.float64:
return Float64Matrix.scalar(scalar, size);
default:
throw UnimplementedMatrixException(dtype);
}
}