I have a huge matrix defined using constant array function and it allocates so much memory preventing the calculation. Therefore, I would like to change the constant array matrix into sparse matrix which stores only nonzero elements enables reducing the memory size.
Here is just a simple example. Let's say I have a constant array deneme
and convert it into sparse matrix deneme2
as below:
deneme = ConstantArray[0, {3, 3}];
deneme[[1, 1]] = 6; deneme[[1, 2]] = 3; deneme[[1, 3]] = 5;
deneme[[2, 1]] = 4; deneme[[2, 2]] = 7; deneme[[2, 3]] = 8;
deneme[[3, 1]] = 1; deneme[[3, 2]] = 5; deneme[[3, 3]] = 9;
deneme2 = SparseArray[deneme];
How could I see the total memory the two matrices, deneme
and deneme2
allocate?
Does ByteCount
work correctly, since the sparse matrix stores much more byte than constant array matrix ?
ByteCount
? . TryByteCount/@ {deneme, deneme2}
. Does this answer your question? How to relate memory usage with occupied positions of SparseArrays? $\endgroup$