Answer the question
In order to leave comments, you need to log in
How to fill a large matrix with numbers?
There is a matrix 12x31.
I declare it like this
let matrix = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
];
Answer the question
In order to leave comments, you need to log in
[...Array(12)].map(row => [...Array(31)])
fill with numbers - how, from 0 to 12*31?
[...Array(12)].map((row, x) =>
[...Array(31)].map((col, y) => x * 31 + y)
)
Easier: npm install ml-matrix
Documentation
import { Matrix } from 'ml-matrix';
const matrix = new Matrix(12, 31);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question