Matrix.fromColumns constructor

Matrix.fromColumns(
  1. List<Vector> source, {
  2. DType dtype = DType.float32,
})

Creates a matrix with predefined column vectors

A simple usage example:

import 'package:ml_linalg/matrix.dart';
import 'package:ml_linalg/vector.dart';

void main() {
  final matrix = Matrix.fromColumns([
    Vector.fromList([1, 2, 3, 4, 5]),
    Vector.fromList([6, 7, 8, 9, 0]),
  ]);

  print(matrix);
}

The output:

Matrix 5 x 2:
(1.0, 6.0)
(2.0, 7.0)
(3.0, 8.0)
(4.0, 9.0)
(5.0, 0.0)

Implementation

factory Matrix.fromColumns(
  List<Vector> source, {
  DType dtype = DType.float32,
}) {
  switch (dtype) {
    case DType.float32:
      return Float32Matrix.fromColumns(source);

    case DType.float64:
      return Float64Matrix.fromColumns(source);

    default:
      throw UnimplementedMatrixException(dtype);
  }
}