operator / method

Array2d operator /(
  1. Array2d b
)

Divide two arrays with the same size

Examples

var a = Array2d([
  Array([2, 2, 2]),
  Array([2, 2, 2]),
  Array([2, 2, 2])
]);
var b = Array2d([
  Array([2, 2, 2]),
  Array([2, 2, 2]),
  Array([2, 2, 2])
]);

print(a / b);

/* output:
Array2d([
  Array([1, 1, 1]),
  Array([1, 1, 1]),
  Array([1, 1, 1])
]);
*/

Implementation

Array2d operator /(Array2d b) {
  _checkArray2dColumnsLength(this);
  _checkArray2dColumnsLength(b);
  _checkArray2dLength(this, b);

  var aRows = length;
  var aColumns = this[0].length;

  var c = Array2d.fromArray(this); // make a copy of local

  for (var i = 0; i < aRows; i++) {
    //
    for (var j = 0; j < aColumns; j++) {
      // bColumn
      c[i][j] /= b[i][j];
    }
  }

  return c;
}