can't this whole loop be replaced with a DenseMatrix.tabulate?