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

learn more… | top users | synonyms

22
votes
2answers
1k views

Using the Krylov method for Solve: Speeding up a SparseArray calculation

I'm trying to implement this Total Variation Regularized Numerical Differentiation (TVDiff) code in MMA (which I found through this SO answer): essentially I want to differentiate noisy data. The full ...
18
votes
1answer
403 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: ...
16
votes
3answers
996 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 ...
15
votes
6answers
725 views

Matrix Rotation

If I have a matrix of any size, say $\begin{pmatrix} 72 & 32 & 64 \\ 18 & 8 & 16 \\ 63 & 28 & 56 \\ \end{pmatrix}$ $\begin{pmatrix} 72 & 32 \\ 18 & 8 \\ 63 ...
15
votes
1answer
347 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. ...
15
votes
0answers
201 views

Simple Matrix multiplication takes very long

Bug introduced in 10.1.0 I came across some strange behaviour during a computation involving matrices with symbolic values. It is reproduced below. Multiplying a random 30x30 array with symbolic ...
14
votes
1answer
215 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: ...
13
votes
1answer
387 views

How to use SparseArray in CUDA?

Sparse arrays are widely used in many scientific applications where memory and time are strictly limited. For a considerable speedup one can use CUDA. Since Mathematica 8 we can conveniently use CUDA ...
12
votes
2answers
954 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 ...
12
votes
2answers
211 views

Bug with SparseArray selector in Pick

I have created a notebook with two cells. This is the content of the first: ...
11
votes
1answer
2k 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 ...
11
votes
2answers
243 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 ...
10
votes
2answers
575 views

Speeding up construction of simple tridiagonal matrix

I have the following code to construct a tridiagonal matrix: ...
10
votes
1answer
196 views

Sporadic bugs in multidimensional SparseArray objects

Udate This SparseArray[] bug is (apparently) fixed on version 10.0 ...
10
votes
1answer
767 views

Sparse convolution of sparse arrays

The documentation for ListConvolve mentions that "ListConvolve works with sparse arrays", which is true. The result, however is never sparse, eg: ...
9
votes
2answers
500 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 ...
9
votes
2answers
218 views

Additive SparseArray Assembly

The goal is to assemble a SparseArray in an additive fashion. Let us assume we have a large List of indices (some will be ...
9
votes
2answers
371 views

Speed up 4D matrix/array generation

I have to fill a 4D array, whose entries are $\mathrm{sinc}\left[j(a-b)^2+j(c-d)^2-\phi\right]$ for a fixed value of $\phi$ (normally -15) and a fixed value of $j$ (normally about 0.00005). The way ...
8
votes
2answers
181 views

Analytic determinant of a sparse 25x25 matrix?

I would like to compute the analytic determinant of the following sparse matrix ...
8
votes
2answers
731 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 ...
8
votes
1answer
1k 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 ...
8
votes
1answer
192 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. ...
7
votes
1answer
157 views

Instant kernel crash when using `+=` on `SparseArray` with repeated entries

Bug introduced in 5.2 and fixed in 10.1.0 Not sure if this is known behavior or not, but the following two lines produce an instant kernel crash (I'm using Mathematica 10.0.1 Windows 64-bit): ...
7
votes
1answer
135 views

Possible bug: SparseArray Part assignment loses default value?

fixed in 10.0.2 This sure looks like a bug to me (Mathematica 10.0.0, MacOS): ...
6
votes
2answers
378 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 ...
6
votes
1answer
332 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 ...
6
votes
0answers
181 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 ...
5
votes
4answers
519 views

Elegant mehod of generating this matrix?

Good evening, I need to determine an elegant (as possible) method of computing an nxn matrix below (the matrix shown is just a 16x16 example). I've been toying with For loops, Tables, Bands, ...
5
votes
1answer
222 views

What's wrong with this code to create a matrix?

Here is my code: ...
5
votes
1answer
98 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 100.000.000 by 10 element SparseArray. And fill the two position 1/1 and ...
5
votes
1answer
191 views

Why is Flattening a CoefficientArray so slow?

I have a vector of $n$ degree $n$ polynomials in $(x,y,z)$, each of whose coefficients is an inhomogenous linear expression in $3 n^2$ variables. I want to write down the linear equations in these $3 ...
5
votes
1answer
219 views

Summing tensors in mathematica

How do I perform the following summation in mathematica? \begin{equation} \Sigma_{m=1}^5 e_{ijklm}A^{mn} \end{equation} I have the $e_{ijklm}$ tensor of rank 5 in 5 dimension as a array and $A^{mn}$ ...
5
votes
0answers
106 views

SparseArray internal structure [duplicate]

According to the documentation: SparseArray is treated as a raw object by functions like AtomQ and for purposes of pattern ...
4
votes
3answers
616 views

Finding elements from a sparse matrix

I am dealing sparse matrices of very large dimensions. I need to locate the positive and negative elements of the matrices and make lists of their corresponding positions. Of course I can write a ...
4
votes
3answers
244 views

Constructing Tri-Diagonal Matrices

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 & ... ...
4
votes
3answers
412 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 ...
4
votes
2answers
222 views

Upsampling matrix by inserting zeros inbetween elements

I want to essentially take an image with $n \times n$ pixels and expand it into a sparse array, spacing out the pixels by a factor $2$ or $3$. Each pixel in the input image occupies one of the corners ...
4
votes
1answer
151 views

How can I efficiently ArrayFlatten a matrix of sparse matrices?

I have a matrix of sparse matrices that I want to convert to a sparse block matrix. So, basically I want what ArrayFlatten does, except that I want the output to be ...
4
votes
1answer
110 views

Parallelizing sparse array construction

I have a very large sparse array, and the computation of individual matrix elements is fairly expensive. The Matrix is Hermitian and traceless, so I would like to construct only the sub-diagonal ...
4
votes
1answer
137 views

Assigning Sequence to Part of a SparseArray (bug?)

Part ▪ You can make an assignment like t[[spec]]=value to modify any part or sequence of parts in an expression. ▪ If ...
4
votes
1answer
59 views

SparseArray output triggers “unsafe dynamic content” warning

The first basic example in the documentation of SparseArray: ...
4
votes
2answers
131 views

Values (or positions) of array row elements within a specified number of positions from target value

I have the need to collect values from the rows of rectangular arrays of arbitrary precision integers, given a target element value and allowed "distance" (positions +/- within the row from found ...
4
votes
1answer
178 views

Efficient Dyson series implementation

I'm trying to implement a Dyson series \begin{array}{lcl} U(x,x_0) & = & 1 + \int_{x_0}^{x}{dy_1V(y_1)}+\int_{x_0}^x{dy_1\int_{x_0}^{y_1}{dy_2V(y_1)V(y_2)}}+\cdots \\ & &{} + ...
4
votes
0answers
66 views

How can I force the use of sparse diagonalization methods?

When I evaluate the Eigenvalues function on a very large (e.g. 2^16 x 2^16) sparse matrix, Mathematica says something like: Because finding 65536 out of the ...
4
votes
0answers
40 views

Bug? Kernel Crash on SparseArray access [duplicate]

Bug introduced in 5.2 and fixed in 10.1.0 The following simple code s = SparseArray[{}, {10, 10}] s[[1, {1, 2, 3, 1, 1}]] = {a, b, c, d, e} on my machine ...
3
votes
3answers
409 views

Support for Compressed Sparse Column sparse matrix representation

Is there native support for Compressed Sparse Column (CSC) format for sparse matrices, like importing and manipulating them?
3
votes
1answer
527 views

How to get the determinant and inverse of a large sparse symmetric matrix?

For example, the following is a $12\times 12$ symmetric matrix. Det and Inverse take too much time and don't even work on my ...
3
votes
1answer
117 views

Opposite function to Normal

Is there any function opposite to Normal? For example, let as say that I have an SparseMatrix A, then, let as say that for convenience for a certain operation like Packing, I convert it into an Array ...
3
votes
1answer
299 views
3
votes
1answer
258 views

Efficiently importing XPM matrix data into Mathematica

The XPM file format is an image file format. Although it is primarily intended for icon pixmaps, it can also be used to store matrix data. For example, the GROMACS chemical simulation package uses ...