getColumn method

Array? getColumn(
  1. int column
)

Return Array with the column elements

  • column column number.
  • FormatException: columns number must be in Array2d.

Examples

var matrix = Array2d.empty();
var line = Array([1.0, 2.0, 3.0]);

matrix.add(line);
matrix.add(line);
matrix.add(line);

print(matrix.getColumn(1));

/* output:
Array([2.0, 2.0, 2.0])
*/

Implementation

Array? getColumn(int column) {
  var aColumn = Array.empty();
  for (var i = 0; i < l.length; i++) {
    var row = this[i];
    if (column >= row.length) {
      throw FormatException('columns number must be in Array2d');
    }
    aColumn.add(row[column]);
  }

  return aColumn;
}