# Questions tagged [sparse-arrays]

Questions on the construction and manipulation of sparse arrays in Mathematica, with functions like SparseArray[] and Band[].

260 questions
Filter by
Sorted by
Tagged with
39 views

39 views

### How do I pass indices to a function when constructing a SparseArray?

I am trying to speed up my Mathematica code, so instead of testing and calculating the same thing again and again I want to save the result in a SparseArray. The goal is to generate a matrix which I ...
57 views

### Import and export a list of SparseArrays efficiently?

I have a list of integers dims and a list of SparseArrays bdrs (representing a chain complex ...
44 views

### How to find the rank of a sparse-array list without memory leaks?

I have a very wide list of sparse arrays (I basically just used the numbers as an encoding mechanism for vectors of polynomials), and I want to find out whether they're linearly independent. How ...
143 views

### Efficiently populate sparse matrix with band structure

I'm trying to efficiently populate elements of a very large (2^20 x 2^20) symmetric matrix with 1s - luckily the matrix is very sparse, <0.1% filling. Further, the matrix has a very well defined ...
223 views

### Multiplying two complex SparseArray objects, yielding empty SparseArray crashes kernel

Problem: When I multiply together two sparse matrices that should give back the 0 matrix, where at least one element among the two is complex and at least one is not an exact number, the kernel ...
115 views

### SparseArray to list of lists (column entries) efficiently?

Suppose we have a very big very sparse matrix, e.g.: ...
49 views

### How to apply PolynomialMod to a SparseArray?

I have a list bdrs of SparseArrays, whose entries are polynomials in the variable t with ...
148 views

### Count for SparseArray

Why does Count not work with SparseArrays, and is there any function I can use to replace it? What would be an efficient ...
81 views

### Memory usage for smallest eigenvalues

I have a bunch of hermitian matrices which are huge (of order 2^17 x 2^17) but extremely sparse so that, when I build the matrices, the usage of RAM is low (say of order 1 GB or similar). The ...
255 views

### Reusing PARDISO symbolic factorization

Is there a way to do this natively in Mathematica? I read in several places that this is possible with LibraryLink, but I don't have a lot of experience with C and so I'm having trouble implementing ...
63 views

### Arnoldi method misses eigenvalues degeneracies for very sparse matrices

I am here to signal a problem very very similar to the one already discussed here Wrong eigenvalues from a sparse matrix In particular, I have a very sparse matrix and I am asking just few dominant ...
85 views

### How to speed up my code using Sparse-array possibly?

I created two loops using Parallel table and a table. The outer loop causes a (nstates by nstates) dimension matrix and the inner loop calculates the matrix elements based on their position in the ...
51 views

558 views

### Optimising subdiagonal shift matrix generation time

I want a square matrix $A$ such that $$A_{i,i-1} = 1 \ \forall i\\ A_{i,j} = 0 \text{ for } \ j \ne i-1$$ I have tried ...
347 views

### Lowest Magnitude Eigenvalues of Large Sparse Matrices

I am trying to find the first three lowest eigenvalues of large sparse matrices of size range $10^3 - 10^5$. The matrices depend on some parameter $x$, so I first construct the matrices and then use ...
61 views

### Inverse of Sparse Diagonal Array not Sparse

Kind of bummed that when I take the inverse of a matrix that is a diagonal sparse array, the result in not a sparse array. Further, the time to compute the inverse is the same as the time to compute ...
64 views

### Time used by Mathematica to calculate tridiagonal matrix

I have a question. I need to find the eigenvalues and eigenvectors of a tridiagonal matrix of size NxN. Can you tell me how much time does Mathematica need to do that in minutes? for Size N ...
692 views

### How to generate binary array whose elements with values 1 are randomly drawn

I am trying to generate a binary matrix (whose elements are 0 or 1) of dimension 20x20. To do this, I want to supply as input the number of matrix elements that will take value 1. After, I want to ...
1k views

### Solving “Resistance between two nodes on a grid” problem in Mathematica

In the context of resistor networks and finding the (equivalent) resistance between two arbitrary nodes, I am trying to learn how to write a generic approach in Mathematica, generic as in an approach ...
785 views

The motivation for my question is that I'm creating very large, very sparse symmetric matrices and finding the largest eigenvalue. (Think upwards of $10^5\times 10^5$ size matrices, with at most $10^... 0answers 34 views ### Selecting some vectors from a matrix I am trying to write a code for band matrices that store only the nonzero vectors. For example if I have tridiagonal matrix of size 10, I want to store only the three diagonals as a vectors. n here ... 4answers 1k views ### Set every element to zero in matrix unless it's 1 or 1/2 I have the following code: ... 0answers 175 views ### Matrix-free Arnoldi method for eigensystems I am solving a generalized eigenvalue problem $$\mathbf S\,\mathbf x = \lambda\,\mathbf M\,\mathbf x$$ w/$\mathbf S := \mathbf B\,\mathbf A^{-1}\,\mathbf B^{T}$, and$\mathbf A$is a sparse ... 1answer 232 views ### Bottom-most left-most entries in a sparse array I have a list bdrs of SparseArrays, which represent the boundary matrices of a chain complex$R^{d_0}\overset{\partial_1}{\...
Given $A\!\in\!\mathbb{Z}^{m\times n}$ stored as a=SparseArray[{...},{m,n}], how can I obtain the list of all indices $i\!\in\!\{1,\ldots,m\}$ for which the $i$-th ...