I am writing a java program which involves working with a 1058 X 1058 matrix containing float values. This matrix contains many zero values and so I need to store this as a sparse matrix and later use this matrix to generate a spanning tree. I checked many popular libraries like Colt, Jama, but somehow I am unable to put them to work with my code. I would like to have a coordinate storage system (similar to obtained in matlab using the sparse() function) like this:

```
(1055,1045) 1.0000
(1056,1045) 1.0000
(1057,1045) 1.0000
(1058,1045) 1.0000
(1047,1046) 1.0000
(1048,1046) 1.0000
(1049,1046) 1.0000
(1050,1046) 1.0000
(1051,1046) 1.0000
(1052,1046) 1.0000
(1053,1046) 1.0000
(1054,1046) 1.0000
(1055,1046) 1.0000
```

Can anyone suggest how to go about this?

You can do it quickly without any lib. Create the following class :

```
MatrixIndex implements Comparable<MatrixIndex>
{
private final int _x;
private final int _y;
...
}
```

Then use it in some :

```
TreeMap<MatrixIndex,Double>
```

Cheers

There is a la4j (Linear Algebra for Java) library that handles this with `CRSMatrix`

/`CCSMatrix`

sparse matrix types and `MatrixMarketStream`

class. Here is the brief example:

Source file "matrix.mm" (5x5 matrix with 8 non-zero elements):

```
%%MatrixMarket matrix coordinate real general
5 5 8
1 1 1.000e+00
2 2 1.050e+01
3 3 1.500e-02
1 4 6.000e+00
4 2 2.505e+02
4 4 -2.800e+02
4 5 3.332e+01
5 5 1.200e+01
```

Java source (la4j usage):

```
Matrix a = new CRSMatrix(Matrices.asMatrixMarketSource(
new FileInputStream(new File("matrix.mm"))));
System.out.println("DET(A) = " + a.determinant());
```

About the MatrixMarket format read here. About CRS/CCS formats read here and here.

To generate MatrixMarket output use following code:

```
Matrix a = new CRSMatrix(...);
MatrixStream out = new MatrixMarketStream(new FileOutputStream(
new File("matrix.mm")));
out.writeMatrix(a);
```

Similar Questions

I'm coding the program that using linked list to store a sparse matrix. First I create a class Node contains the index of entry, value of entry and two pointers to next row and next column. Second I

I have a matrix A in CSC-format, of which I index just a single column b = A[:,col] resulting in a (n x 1) matrix. What I want to do is: v = M * b where M is a (n x n) matrix in CSR. The result v i

I'm trying to use large 10^5x10^5 sparse matrices but seem to be running up against scipy: n = 10 ** 5 x = scipy.sparse.rand(n, n, .001) gets ValueError: Trying to generate a random sparse matrix su

I need to create my own coordinate system in UIView, where 0,0 is center of UIView. But I don't know ho to do this. Please help.

I researched a lot on this but couldn't find a practical solution to this problem. I am using scipy to create csr sparse matrix and want to substract this matrix from an equivalent matrix of all ones.

Let A be a sparse matrix in coordinate format [row(int) col(int) val(float)]. If a upper triangular sparse matrix of A is needed, then the same can be obtained using logical indexing like: A = A(A(:,1

I would like to accomplish the following thing. I have a set of PDF files, first I would like to check the origin of the coordinate system. If the origin of the coordinate system for the pdf is not up

Are there any algorithms that allow efficient creation (element filling) of sparse (e.g. CSR or coordinate) matrix in parallel?

I want to plot a sparse matrix in an imagesc type of style (one color for each pixel, and not symbols a la scatter). The matrix consists of blobs that are spread ut over a 10000x10000 square. I expect

I'm working on a toy game engine. I have never been thinking about coordinate system, just accepted them as is, but now I'm a bit confused. So, this is how common game coordinate system looks like (mo

I have a very large and very sparse matrix, composed of only 0s and 1s. I then basically handle (row-column) pairs. I have at most 10k pairs per row/column. My needs are the following: Parallel inser

Say I would like to remove the diagonal from a scipy.sparse.csr_matrix. Is there an efficient way of doing so? I saw that in the sparsetools module there are C functions to return the diagonal. Based

I noticed on Google Summer of Code 2013 that a possible project was implement sparse matrix support for Decision Trees and ensemble methods. Out of curiosity, did this project get anywhere? I really n

I have encountered a difference in how slicing a scipy sparse matrix works in 0.10.0 and 0.10.1. Consider the following piece of code: from numpy import array, ravel from scipy.sparse import csr_matri

I have the quaternion values from a particular coordinate system and I need to map that to Unity's coordinate system (which uses left hand coordinate system). Using (x, y, z) is the axis of Unity's co

I have a transaction dataset with 250000 transactions (rows) and 2183 items (columns). I wanna transform it to a sparse matrix and then do hierarchical cluster on it. I tried package 'sparcl', but it

I would like to extract specific rows and columns from a scipy sparse matrix - probably lil_matrix will be the best choice here. It works fine here: from scipy import sparse lilm=sparse.lil_matrix((10

I have a matrix of factors in R and want to convert it to a matrix of dummy variables 0-1 for all possible levels of each factors. However this dummy matrix is very large (91690x16593) and very spar

I was trying to iterate over the non zero elements of a row major sparse matrix, such as shown below: Eigen::SparseMatrix<double,Eigen::RowMajor> Test(2, 3); Test.insert(0, 1) = 34; Test.insert

We have an application that stores a sparse matrix. This matrix has entries that mostly exist around the main diagonal of the matrix. I was wondering if there were any efficient algorithms (or existin

I've got a scipy.sparse_matrix A and I want to zero-out a decently-sized fraction of the elements. (In the matrices I'm working with today, A has about 70M entries and I want to zero-out about 700K of

I want to create a custom optimized matrix operation (a smart kronecker product based on what I know about the sparse matrices i'm using) using MathNet.numerics for csharp. Is there an accessor to get

I am looking for sparse matrix representation that allow for efficient row and column swaping. The classic representation (by compressed row,compressed column or triplets) seems to only allow to perfo

Who knows how to move from top left coordinate system to the default, where X/Y-axis starts from the left bottom corner (like we always draw them) on QPixmap/Qimage

I'm looking for an a command or trick to convert two arrays to a sparse matrix. The two arrays contain x-values and y-values, which gives a coordinate in the cartesian coordinate system. I want to gro

The question is: Is it possible to create a sparse matrix using the following sparse list implementation? In special, using a class template with a class template (SparseList*>)? I've created a cla

Given an image of size [hh,ww], I would like to create efficiently a sparse matrix of size [hh*ww, hh*ww]. For each 4- or 8-neighbor of a given pixel, the sparse matrix should be filled with a constan

I have a necessity of translating coordinate system of the canvas in paperjs so that topleft of the canvas something other than (0,0) depending on the circumstances.By changing the coordinates I want

Is there any effective implement of the solution for sparse matrix linear equation using CUDA?

Is there an efficient way of converting a sparse matrix in Compressed Row Storage(CRS) format to Coordinate List (COO) format ?

I have a very large (about 91 million non-zero entries) sparseMatrix() in R that looks like: > myMatrix a b c a . 1 2 b 1 . . c 2 . . I would like to convert it to a triangular matrix (upper or lo

Since System.Windows.Media.Matrix doesn't provide Clone() method, what is the best possible approach to clone a matrix. I am right now using the following approaches: Create a new matrix from the ori

I have an array of high dimensional however very sparse matrices. I want to normalize them so that column sums of all matrices sum to one. Here is the sample code I use: bg = matrices{1}; for i = 2:le

I'm trying to figure out how to efficiently solve a sparse triangular system, Au*x = b in scipy sparse. For example, we can construct a sparse upper triangular matrix, Au, and a right hand side b with

I have an original matrix that looks something like this: (32, 69901) 1 (108, 69901) 1 (32, 69902) 1 (108, 69903) 1 (108, 69904) 1 (432, 69905) 1 (432, 69906) 1 (432, 69907) 1 I want to separate the

given is a Cartesian coordinate system and a point(x,y) within this system. For example a point p has the coordinates (-12,2): | | p | | ------------------+------------------> | | | | Now I need

I just started to learn to program in Python and I am trying to construct a sparse matrix using Scipy package. I found that there are different types of sparse matrices, but all of them require to sto

I am trying to compute nearest neighbour clustering on a Scipy sparse matrix returned from scikit-learn's DictVectorizer. However, when I try to compute the distance matrix with scikit-learn I get an

Does anyone know how to perform svd operation on a sparse matrix in python? It seems that there is no such functionality provided in scipy.sparse.linalg.

I'm sorry if this is explained clearly in the scipy.sparse documentation. When using scipy, what function would you recommend using to solve a sparse positive definite linear system of equations? I wa

I would like to take column and row names from a text file and build a sparse matrix using the row and column information (the algorithm can be found in the description below). I have a working soluti

I can get image coordinate using this code.But I want to do the same by using Matrix. private int _angle = 90; float scaleFactorX = (float)resizeWidth / (float)originalWidth; float scaleFactorY = (f

I recently satrted learning OpenGL, and it seems pretty intuitive so far, but this I am stuck on. How can I change the settings so that OpenGL uses a pixel based coordinate system instead of what it u

I'm making a little program to make a representation of sparse matrixes (a matrix with a lot of elements equal to zero). Represented like this page 108 (I think watching at the figure is enough to und

I'd like to make a Cartesian Coordinate System in a Windows form and be able to plot (x,y) coordinates in it. How do i do this? I already did my research but unfortunately i only land on charts and

I have a huge sparse matrix in Scipy and I would like to replace numerous elements inside by a given value (let's say -1). Is there a more efficient way to do it than using: SM[[rows],[columns]]=-1 H

I have built a small code that I want to use for solving eigenvalue problems involving large sparse matrices. It's working fine, all I want to do now is to set some elements in the sparse matrix to ze

I have a large scipy sparse matrix, which is taking up >90% of my total system memory. I would like to save it to disk, as it takes hours to build the matrix... I tried cPickle, but that leads to a

I currently want to multiply a large sparse matrix(~1M x 200k) with its transpose. The values of the resulting matrix would be in float. I tried loading the matrix in scipy's sparse matrix and by mul

I have to create an image with very large resolution, but the image is relatively sparse, only some areas in the image need to draw. For example with following code /* this take 5GB memory */ final