I have a 3D NumPy array that I want to convert to a 3D sparse matrix in Python. I looked up scipy.sparse module and only found 2D sparse matrix implementations. For example,
Input:
array([[[0],
[0],
[1],
[0],
[1],
[0],
[0]],
[[1],
[0],
[1],
[0],
[0],
[0],
[0]]])
Output:
(0,0,2) 1
(0,0,4) 1
(0,1,0) 1
(0,1,2) 1
How would do this?
scipy.sparsecode only works with 2d. What do you want to do with the sparse matrix once you have it? It's one thing to represent the values, it's quite another to do something meaningful with them.dokorlilimplementation in 3d, but without the algorithms that letcsrandcscimplementations do matrix math, they won't be particularly useful. If the matrix is some sort of transfer function you would probably be better flattening the input and output and storing the transformation in 2D. This is how, for example, a 4D symmetric transform can be represented in 2D via Voigt Notation