- The best and easiest or even reliable way to store matrix elements in a database. In addition, I need to multiply two matrices and make the operation dynamic. So will storing data create any problems for the task?
To begin with, both approaches are valid, but the second is not enough, as you wrote. You should have some other information, such as the length of the rows or the indices (row, column) of each element to store the matrix as a 1D array. This is usually done for sparse matrices, where there are many zeros surrounding the values ββgrouped on either side of the diagonal.
Storing a matrix in a database and managing it in memory are two separate things.
Tasks such as multiplication require (rows, columns) indexes. Storing the matrix as a 2D array means you get them, so no other information is required. A 1D array also needs this information, so you have to provide it.
The advantage goes into a 1D array for sparse matrices. In this case, you do not need to keep the null values ββoutside the bandwidth, but your operations, such as addition and multiplication, become more complicated for the code.
duffymo
source share