# Questions tagged [sparse-arrays]

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

78 questions
Filter by
Sorted by
Tagged with
3k views

### What are SparseArray Properties? How and when should they be used?

A strange undocumented form of SparseArray is increasingly used in answers on this site: ...
• 272k
1k views

### How to interpret the FullForm of a SparseArray?

SparseArrays are atomic objects, but they do have a FullForm which reveals information about them. What is the meaning of the ...
• 236k
781 views

The goal is to assemble a SparseArray in an additive fashion. Let us assume we have a large List of indices (some will be ...
• 758
8k views

### Find the eigenvector associated with the smallest eigenvalue, not smallest in magnitude

I am trying to find the eigenvector of a $20000 \times 20000$ sparse matrix associated with the smallest eigenvalue. I realized that the smallest eigenvalue might be negative; for example, if the ...
• 405
2k views

### Efficient way to combine SparseArray objects?

I have several SparseArray objects, say sa11, sa12, sa21, sa22, which I would like to combine into the equivalent of {{sa11, sa12}, {sa21, sa22}}. As an example, I ...
239 views

### How to relate memory usage with occupied positions of SparseArrays?

What is the relation of memory usage of a SparseArray and the number of its occupied positions? Let's say you build a $100000000 \times 10$ ...
2k views

### Speeding up generation of block diagonal matrix

I'm struggling with the following problem. I have $48$ square matrices (full, filled with real machine precision numbers, thus are packed, all different) of size $128$. I wolud like to place them on a ...
• 3,518
2k views

### Efficient by-element updates to SparseArrays

I have a very large SparseArray called A. What is the most efficient way to update say element ...
• 73.2k
2k views

### Using ReplaceAll on SparseArray

I'm using SparseArray in a notebook in which I am doing complex conjugation manually, i.e. writing $\sqrt{-1}$ as i and applying ...
• 503
880 views

### Speeding up construction of simple tridiagonal matrix

I have the following code to construct a tridiagonal matrix: ...
• 19.9k
763 views

### Why won't SparseArray let me store values with the head List?

When you attempt to define a SparseArray with elements that have the head List it complains: ...
• 272k
1k views

### Import Excel sheet into 3D array?

I have an excel spreadsheet that I would like to plot in a 3D graph using mathematica. The X and Y values are the location of the cell, and the Z value is the number of the scale. How can I import ...
• 775
2k views

### A geometric multigrid solver for Mathematica?

Cross posted to community.wolfram.com Mathematica ships a variety of linear solvers through the interface LinearSolve[A, b, Method -> method] the most ...
330 views

### Fast way to reassemble SparseArrays

I often have to deal with nonlinear shape optimization problems involving curves or surfaces surfaces. A classical example is Plateau's problem. No matter if I use gradient-based techniques (such as ...
334 views

### Adding two SparseArrays produces zeros in the reported "NonzeroValues"

When two SparseArrays are added together and new zero values are created, these new zero values are reported as "NonzeroValues". Example, produced with Mathematica version 10.2: ...
• 73
1k views

### SparseArray row operations

Given a large (very) sparse matrix, A, how can I efficiently "operate" on only the nonzeros in a given row? For example: For each row in A, generate a list of column indices that have a magnitude (...
• 758
1k views

### LinearSolve and Krylov Method options

I need to solve a large, sparse, linear system. At some point Method -> "Multifrontal" fails and a bit later also "Pardiso" ...
• 7,123
289 views

...
• 7,253
519 views

### Adding three integer sparse matrices is very slow. Adding only two is fast

Bug introduced in 9.0.0 and fixed in 10.0.0 Adding more than two sparse matrices in one step in Mathematica 9 is very slow (in fact I couldn't even wait for it to finish). Here's an example. Let's ...
• 236k
537 views

### Building sparse array from packed arrays

Suppose I have two large packed arrays a and b, that respectively contain the position of the elements of a square matrix (i.e. <...
468 views

### directly change the background value of a SparseArray?

given a SparseArray s = SparseArray[{1, 10} -> 1, {1, 10}, a] I can extract the background value (see What are SparseArray ...
• 39k
476 views

• 1,866
473 views

### Temporal database reconstruction in mathematica

<EDIT> after some internet research I found the database domain that deals with this kind of thing: Temporal Databases. I think my question therefore becomes how to reconstruct a temporal ...
• 558
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 ...
880 views

### Analytic determinant of a sparse 25x25 matrix?

I would like to compute the analytic determinant of the following sparse matrix ...
• 12k
4k views

### How to work around Mathematica hanging when showing a large SparseArray?

Bug introduced in 9.0 and fixed in 9.0.1 In Mathematica 9, if I display any large SparseArray object in the default way (which looks something like ...
• 236k
197 views

### What are valid settings for the TreatRepeatedEntries sparse array option?

There is a system option that controls how to build sparse arrays when a position is assigned more than one value. The default setting is First, meaning that all ...
• 236k
890 views

### Replace diagonal elements in sparse matrix

I am interested in replacing all elements in a diagonal of a sparse matrix with zero. Currently, I do it in the following manner: ...
• 2,019
2k views

### Exporting a Large Multidimensional Sparse Array

I'm trying to export a sparse array from Mathematica to share with collaborators who primarily use Matlab. The sparse array in question is 4 dimensional, (72 x 93 x 94 x 172) with ~4M non-zero ...
• 9,652
569 views

### Calculating the rank of a huge sparse array

By virtue of the suggestion in my previous question, I constructed the sparse matrix whose size is $518400 \times 86400$, mostly filled with $0$ and $\pm 1$. Now I want to calculate its rank. Since <...
• 445
313 views

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

Suppose we have a very big very sparse matrix, e.g.: ...
• 1,155
204 views

### Rank of singular, large, sparse matrices

I need to find the rank (and eventually do the Gaussian elimination) of a large, sparse, non-square matrix of integers. There are a few methods in Mathematica to find the rank of a non-square matrix (...
• 998
5k views

### How to export an output matrix obtained in mathematica to a matrix in python with the correct format?

I have a large sparse matrix as the output and I want to save the output and open it as a matrix in python. The output is a 6000 x 6000 matrix and I don't know how to make changes to the file such ...
146 views

### LibraryLink: Create SparseArray directly from row pointers and column indices

In Mathematica, sparse arrays use a CSR representation. Suppose I already have data in this format. Is there a way to create an MSparseArray from it directly with ...
• 236k
1k views

### How to create a large sparse block matrix

I need to generate a very large sparse block matrix, with blocks consisting only of ones along the diagonal. I have tried several ways of doing this, but I seem to always run out of memory. The ...
• 81
Fractional Calculus Course, we are instructed to create an $n \times n$ Tri-Diagonal matrix in the form of: \begin{array} a A &= \begin{bmatrix} 2 & -1 & 0 & 0 & ... &...