Questions tagged [sparse-arrays]

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

Filter by
Sorted by
Tagged with
6
votes
1answer
132 views

Nonsparse SparseArray crashes the Kernel

Bug introduced in 10.0 and fixed in 11.1 On Windows 10, 64 bit, version 11.0.1, my kernel just started crashing for no reason as for as I can see. Does/should the following crash your kernel? ...
3
votes
0answers
53 views

Map entries of StructuredArray

I have the following defintion arr = SymmetrizedArray[{1, 2} -> 1, {4, 4}, Antisymmetric[{1, 2}]] which gives a ...
0
votes
0answers
52 views

How to modify the default value of a `SparseArray` without intermediate non sparse matrices [duplicate]

How to modify the default value of a SparseArray? All of my ideas doesn't work, because of the ReadProtected attribute. Is there ...
6
votes
2answers
226 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 ...
7
votes
1answer
211 views

Bug? Strange behaviour of FullSimplify when checking an equality of SparseArray's

Edit (15 Dec '16): bug noticed in v11.0 and reported as CASE:3796403. Edit (03 May '17): bug fixed in v11.1 (verified in v11.1.1). I stumbled upon the following strange behaviour. Disclaimer: I ...
7
votes
4answers
407 views

How to find position where a sequence drops off to zero

Suppose I have a sequence seq = {0,0,0,1,2,3,1,0,0,0,4,5,8,0} and I want to find the first position after which the sequence drops to zero (which in this case, is ...
0
votes
1answer
213 views

How to build a histogram from the mean of 100 matrices

I have a matrix that looks like this: ...
0
votes
0answers
32 views

Sparse (Weighted) Adjacency Matrix & SparseArray: encoding multiple weights at a given edge [duplicate]

Context Below is just an arbitrary example. It is not perfect, but hopefully it serves the point of what I would like to accomplish. Say you have a sparse adjacency matrix, $\bf{A}$, where a value ...
2
votes
1answer
85 views

How to fill in matrices by enforcing a condition on each entry quickly?

In the process of solving a 3D time-dependent PDE, I need to fill several matrices which their sizes are quite high. These matrices are constructed based on the radii of the mesh nodes in the 3 ...
5
votes
3answers
117 views

Sparse array approach to generate a Colm Mulcahy matrix

I wrote: ...
2
votes
1answer
1k views

How to find position of non-zero elements in SparseArray without converting to a dense object

Overview So I have a SparseArray, sparse, constructed from a list of rules, with the dimension options. Given a row, I want to know where the values are non-zero. ...
1
vote
1answer
201 views

How to create a matrix with some conditions?

I want to create an $n \times n$ matrix (eg. $n=5$) using the following steps: 1) The entries aii (i = 1, ..., n) that form the main diagonal of a square matrix are 0 (aii=0); In C++, the element of ...
6
votes
1answer
237 views

Pardiso Linear Solve Method

It seems that "LinearSolveMethod" -> {"Pardiso"} is not available on the Raspberry Pi 3 version (10.3, 32-bit Linux, ARM) of Mathematica. Is there a package that ...
1
vote
0answers
44 views

Looking for a package for data on (sparse) uniform grids

I have large amounts of sparse 2d and 3d "volumetric" data, i.e. fixed data associated with positions in a uniform (integer coordinate) grid. I think of it as partial function $$f: \mathbb Z^n \to D.$...
4
votes
1answer
179 views

How does AdjacencyLists work on SparseArray

I have been working with large SparseArray and have noticed the properties are very very useful and fast. I wanted to manipulate my large sparse array in ways similar to the properties. Looking at the ...
6
votes
2answers
2k 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 ...
4
votes
1answer
586 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 ...
1
vote
1answer
149 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 ...
4
votes
0answers
91 views

Why isn't SparseArray working in this case?

This works: SparseArray[{{1, 1} -> 1, {2, 2} -> 2}]\ (* {{1, 0}, {0, 2}} *) This works: ...
6
votes
1answer
208 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 ...
11
votes
2answers
485 views

Why is IdentityMatrix not defined as a SparseArray by default?

Simple (possibly silly) question: why are IdentityMatrix, DiagonalMatrix, ConstantArray ...
1
vote
1answer
158 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 ...
12
votes
1answer
196 views

Something wrong when I apply Derivative on a SparseArray

Bug introduced in v5.0 or earlier, and persisting through v11.0.1 or later There, I create a SparseArray using command ...
10
votes
2answers
156 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 ...
10
votes
1answer
160 views

Possible Bug in LinearSolveFunction with Sparse Vectors

Bug introduced in 5.0 and fixed in 11.0 LinearSolveFunction is new in 5.0 Consider the following set of equations and corresponding variables: ...
0
votes
0answers
386 views

How to compile code that involve sparse array?

I have the following code ...
7
votes
3answers
694 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 ...
4
votes
1answer
197 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 ...
1
vote
3answers
2k 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: ...
17
votes
2answers
240 views
4
votes
1answer
435 views

efficient elementwise multiplication of SparseArray vector and matrix

I have a large $d\times d$ SparseArray $P$, and I want to multiply a vector (also a SparseArray) $v$ of length $d$ elementwise ...
11
votes
4answers
873 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 ...
5
votes
4answers
590 views

Constructing a large tridiagonal matrix with alternating signs

What is the best way to construct a large tridiagonal matrix, in the following form (notably with alternating signs)? $\mathbf M = \begin{pmatrix} 0 & a & 0 & 0 & 0 & \cdots \...
4
votes
0answers
589 views

Finding eigenvalues in Mathematica: why so slow?

I am trying to find the eigensystem of a large sparse real symmetric matrix, and I only need the lowest 40 or so eigenstates. The relevant code is as follows: ...
0
votes
1answer
329 views

LinearSolve on non-square matrices?

I just came across a strange behaviour for LinearSolve (on Mathematica 8.0.0.0). Consider the following definitions: ...
5
votes
4answers
231 views

Add to matrix missing elements (for list of time series)

This question is an extension of the 43122. I’ve looked through many interesting post (like this) but (as always) missed the direct matching. So the setting is simple: ...
1
vote
1answer
63 views

Assemble rule replacement from pairs of positions

I want to create a rule replacement list, which I then use to create a SparseArray. The input is a list of positions of the from ...
4
votes
3answers
188 views

Problem with Conditionals: Why does mathematica add an extra empty list to my output

I have a set of positions where I want to slice a list of numbers. If I Total the values in that list, and they are greater than or equal to 1, I want to remember ...
0
votes
1answer
80 views

Timing and memory use is critical:fast partitioning of binary sparse array

I do experiments were I measure a signal, and I need to know at what time points it is above a threshold. If at a given time point, the signal is above the threshold, then a '1' gets put into the ...
0
votes
0answers
194 views

What is stored for a sparse matrix in memory? [duplicate]

I am wondering if a sparse matrix is stored in memory as a list which is its ArrayRules? The reason to ask this is I am trying to write a function to produce a large sparse matrix. However, I am not ...
2
votes
0answers
505 views

How to solve lowest eigenvalue with Lanczos or Arnoldi algorithm? [closed]

By setting Method->Arnoldi in Eigensystem I was able to solve lowest eigenvalue and eigenstate of a large sparse matrix. ...
15
votes
0answers
590 views

Efficient solution of huge sparse linear system

I'm trying to improve efficiency of my code in which main task is a solution to huge (~$10^4\times 10^4$) but sparse linear system $$Ax=b$$ (In fact my aim is to solve nonlinear equations $F(x)=0$, ...
23
votes
2answers
826 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 ...
19
votes
1answer
1k views

Sparse Cholesky Decomposition

I am working with square matrices with a special form, which for large rank ($> 100,000$) would be best stored and manipulated as a SparseArray. I believe that ...
2
votes
0answers
43 views

Why variable in SparseArray can't be replaced? [duplicate]

SparseArray[{1, 1} -> t] /. t -> 1 Still contains t. Why t is not replaced by 1?
6
votes
1answer
217 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: ...
9
votes
2answers
307 views

Does LinearSolve know that I gave it a Sparse lower triangular matrix?

Let $\mathbf L$ be a nonsingular numeric (non-symbolic) large, lower triangular sparse matrix. Let $\mathbf b$ be an appropriately sized vector. I want to solve $\mathbf L\mathbf x=\mathbf b$. ...
20
votes
1answer
336 views

What are pattern sparse arrays and how do I use them?

I found a few references to something called a "pattern sparse array" that does not contain any values, only positions. What is this data structure? How and when do I use it? From the documentation ...
6
votes
3answers
432 views

How to populate a large sparse array efficiently

I am trying to populate a large 2D sparse array and sum up all the columns at the end. I tried generating a set of rules and then generate a matrix using SparseArray or break the data into chunks but ...
2
votes
0answers
113 views

How to speed up summing a large number of vectors

First let me explain what I am trying to do in my code. Assume that I send a very short chirp (2,000 ms long) into a domain filled with 20,000 particles randomly scattered in the domain. The ...