columnMeans method

List<Complex> columnMeans()

Calculates the mean value for each column in the matrix.

Returns a list of mean values, one for each column.

Example usage:

final matrix = Matrix([
  [1, 2],
  [3, 4],
  [5, 6]
]);
final means = matrix.columnMeans();
print(means);  // Output: [3.0, 4.0]

Implementation

List<Complex> columnMeans() {
  List<Complex> sums = List.filled(columnCount, Complex.zero());
  for (var row in _data) {
    for (int j = 0; j < columnCount; j++) {
      sums[j] += row[j];
    }
  }
  return sums.map((sum) => sum / rowCount).toList();
}