# Tagged Questions

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

100 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 ...
58 views

### Why am I losing precision in computation of eigenvectors of sparse matrices?

I compute the eigenvectors and eigenvalues of the same matrix in its dense and sparse version. The eigenvalues are the same to great precision, but the eigenvectors are not: when I compute the ...
32 views

### Converting a list of lists of indices into a sparse matrix of ones and zeros

I have data formatted like {{a,b},{c,d},{e,f}} where each entry is an integer. I need to turn this in to a sparse array with entries ...
73 views

### Why isn't SparseArray working in this case?

This works: SparseArray[{{1, 1} -> 1, {2, 2} -> 2}]\ (* {{1, 0}, {0, 2}} *) This works: ...
102 views

### Efficiently compute this Table of NullSpace

I have two $(2n,2n)$ matrices, $A_1$ and $A_2$, and I would like to compute $$\ker(A_1^p A_2^q -I)$$ for $p,q\leq 2n$. Both matrices are orthogonal and have exactly four non-zeros values on each ...
307 views

### Why is IdentityMatrix not defined as a SparseArray by default?

Simple (possibly silly) question: why are IdentityMatrix, DiagonalMatrix, ConstantArray ...
81 views

### What would be the Mathematica equivalent of sparse in MATLAB?

The sparse function in MATLAB does the following: S = sparse(i,j,v) generates a sparse matrix S from the triplets i, j, and v such that S(i(k),j(k)) = v(k). The ...
150 views

### Something wrong when I apply Derivative on a SparseArray

Bug introduced in v5.0 or earlier, and persisting through v10.4.1. There, I create a SparseArray using command ...
38 views

### Matrix with equations as entries - how to choose them and solve them

I have a matrix in Mathematica, which I have built using Normal[SparseArray]. Each entry of this matrix is an equation in one variable. What I need to do is 1) to select some of the entries of the ...
121 views

### Using Cases to pick out entries of a SparseArray

I'm trying to use a SparseArray for some large homological algebra calculations. I'd like to find indices of a SparseArray ...
118 views

### Possible Bug in LinearSolveFunction with Sparse Vectors

Bug introduced in 5.0 and persists through 10.4.1 LinearSolveFunction is new in 5.0 Consider the following set of equations and corresponding variables: ...
76 views

### How to compile code that involve sparse array?

I have the following code ...
163 views

### Nonzero element positions of a matrix

Let m={{1, 2, 0}, {4, 0, 9}}; I want to find the position of every nonzero element of the above matrix. The code ...
65 views

### How to create overlapped block matrices and simplify the result

This is sort of a duplicate of Creating overlapped block matrices, but the question wasn't fully answered since the OP never returned to clarify. I am using Kuba's answer for FEM, but I have been ...
90 views

### How to convert a matrix into a sparse matrix [duplicate]

If I have a matrix: row 1)1 0 0 4 row 2)0 0 0 0 row 3)5 1 0 0 row 4)0 5 0 0 row 5)0 0 0 9 How would I put it in a sparse matrix format: ...
60 views

...
107 views

### efficient element wise multiplication of SparseArray vector and matrix

I have a large SparseArray $P$ of dimensions $\{d,d\}$ and I want to multiply a vector (also a SparseArray) $v$ of length $d$ ...
266 views

### How to convert a sparse matrix to a list of sparse arrays?

I have a matrix stored as a SparseArray. How can I convert it to a List of its rows, where each row is stored as a ...
298 views

140 views

### When are sparse arrays effective?

Sparse arrays are not effective in Mathematica 10. More computational time is needed to perform arithmetic operations on sparse arrays. Their size is also bigger than normal arrays. Here is a simple ...
253 views

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

I would like to compute the analytic determinant of the following sparse matrix ...
73 views

### Approximate inverse of large sparse matrix with small diagonal element

I need to find inverse of a large sparse matrix with small diagonal element. I follow this question - Is there any way to obtain an approximate inverse for very large sparse matrices? and try to use ...
147 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 ...
67 views

### Non-numeric elements in banded sparse array

The documentation mentions that "the elements in SparseArray need not be numeric", although "the individual elements of a sparse array cannot themselves be lists." ...
313 views

### Simple Matrix multiplication takes very long

Bug introduced in 10.1.0 and fixed in 10.3.0 I came across some strange behaviour during a computation involving matrices with symbolic values. It is reproduced below. Multiplying a random 30x30 ...
176 views

### Given a matrix of integer, create a matrix with 1 or 0 according to which numbers are in the first matrix

Not sure the title gives the idea of what I need, so here is a sample: I have ten (w) combinations (subsets) of 20 (n) numbers taken 4 (k) at time. I need a matrix of dimension w x n with 0/1 in each ...
194 views

### Memory usage optimization for a large Association/SparseArray

Reformulating my question in simpler terms. Take two lists list1 = RandomInteger[{1, 100000000}, 25000000]; list2 = RandomReal[{1, 10}, 25000000]; Make an ...
635 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: ...
265 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" ...