Skip to main content

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
0 votes
0 answers
74 views

Efficient construction of Hermitian block matrix

I need to construct large Hermitian matrices $H$, which can be built out of blocks. The matrix $H$ is of total size $Lx\times Ly$, with blocks of size $Ly$. For $Lx=5,\,Ly=3$ and $L=2$ (which is the ...
1 vote
1 answer
58 views

Arnoldi method for generalized eigenvalue problem with sparse matrices

I would like to solve a generalized eigenvalue problem involving sparse matrices using the Arnoldi method. I would like to use the Arnoldi method in the hope of speeding up the calculation. Problem is,...
4 votes
2 answers
82 views

Speed up sparse Hermitian matrix-vector product

I am interested in speeding up as much as possible the dot product in the specific case of a multiplication of a $n\times n$ sparse hermitian matrix $H$ (where $n$ is typically large, let's say $\...
6 votes
1 answer
53 views

Workaround for SparseArray "ExplicitPositions" in version 12.0

I have some work that utilizes the "ExplicitPositions" property of Sparse Arrays that was at least available starting at version 13.0. However, I am trying to run some of my work on a ...
10 votes
1 answer
197 views

Fast Sparse Tensor Addition

How can one do a fast sparse tensor addition? Below, I have the following code: We first generate 3 random sparse 1000x1000x1000 tensors with 10^6 entries each. Then, I want to add them. But the usual ...
6 votes
1 answer
139 views

MapIndexed on a table of SparseArray structures produces different output in Mathematica 12 and 14.0

Here is a snippet I use to dynamically define a bunch of functions f[i][x_]: ...
7 votes
3 answers
177 views

Counting non-zero multiplications in large sparse matrix multiplications

Suppose I have several large, fixed, sparse matrices of real-valued entries. To make things simple, assume each is $n \times n$. I will multiply them, e.g., matA.matB.matC. Of course I can reduce ...
3 votes
2 answers
181 views

Creating a sparse matrix

I would like to create the following sparse matrix \begin{equation} A = \begin{pmatrix} a1+b1 t & k-1 & 0 & \ldots &0 \\ a2^{2}+b2^{2} t & a1+b1t & k-2 & \ldots &0 \...
4 votes
5 answers
339 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 ...
5 votes
2 answers
187 views

Efficiently construct a SparseArray of a given "shape"

I have a given SparseArray, let's call it A. I want to construct another SparseArray, let's call it B, which has the same "shape" as A. Right now, I construct B by applying a certain ...
1 vote
1 answer
165 views

Why does using a sparse matrix for least squares instead slow down the speed?

Here is the code. The matrix appears to be relatively sparse in terms of its visual representation, but why does using least squares result in significantly slower speed compared to the previously ...
2 votes
0 answers
69 views

Performance of multiplying two identity matrices

I am running Mathematica 13.3.1.0 on a M1 Mac, and I ran the following codes to check on the time spent on matrix multiplication. ...
0 votes
0 answers
53 views

Sparse Kronecker Product of Pauli Matricies

Suppose I have a list of Pauli matrices (X, Z and I type) paulis = {x,z,z,i,z,x,i,z}; I would like to compute a sparse array equivalent to $$x \otimes z\otimes z \...
1 vote
1 answer
48 views

Best way to Simplify (or applying other functions to) a SymmetrizedArray

I wanted to perform an element-wise Simplify[] on a SymmetrizedArray, but I couldn't find an efficient way to do so without converting it to a "Normal" ...
9 votes
6 answers
3k 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 ...
29 votes
2 answers
1k views

Wrong eigenvalues from a sparse matrix

Bug introduced after 5.0, in or before 8.0 and persisting through 13.3. I notice in the following example that wrong smallest 2 eigenvalues are resulted if calculating from a sparse matrix. But it ...
41 votes
1 answer
2k views

Complex eigenvalues from a sparse Hermitian matrix

Bug introduced in 9.0 or earlier and persisting through 13.3.0. I notice in the following example that wrong complex eigenvalues are resulted if calculating from a Hermitian sparse matrix, which ...
8 votes
1 answer
313 views

How can I prevent conversion of a SparseArray to a DenseArray?

The Problem I'm trying to implement an efficient Whitker-Eliers smoother in Mathematica. In Matlab, this is a few lines of code (taken from the SI of the above paper): ...
5 votes
2 answers
194 views

Reshaping sparse arrays to have extra index

I have an $n \times m \times p$ array, let's call it $r$. I want to obtain an $n \times m \times p \times 5$ array (let's call it $q$) where $q$ is the same as $r$ except that every non-zero component ...
6 votes
1 answer
114 views

DeleteDuplicates without destroying SparseArray

When I use DeleteDuplicates to delete equal rows of a sparse array, the output is not a sparse array anymore. In my application, the sparse arrays are huge but very ...
0 votes
2 answers
59 views

Transformation invariant subspace of three-component array

I have a large sparse array A with dimensions $m \times n \times q $. I also have two transformation matrices, B ($n \times n$) ...
9 votes
7 answers
792 views

How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

I would like to make a rectangular array of 1 and 0 with continuous columns of 1. We are ...
8 votes
1 answer
205 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 (...
4 votes
1 answer
155 views

Third party libraries in LibraryLink

I am trying to use third-party libraries in LibraryLink, but the kernel crashes when I call their functions. In particular, I want to make available some functions of SuiteSparse to manipulate ...
28 votes
4 answers
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 ...
6 votes
2 answers
275 views

Efficient way to compose a SparseArray from system of linear equations [closed]

I have several relations between some variables, e.g. id[1] - id[2] = 0, id[2] = 0. I need to compose a SparseArray that contains the coefficients. In that example,<...
6 votes
1 answer
159 views

Minimizing computational time for a quantum walk problem

Any suggestions as to how to speed up the computational time for this quantum walk problem which is coded using a normalized SparseArray coin operator as follows: ...
5 votes
1 answer
149 views

How could I see the memory use on sparse array and constant array matrices? What is the advantage? [duplicate]

I have a huge matrix defined using constant array function and it allocates so much memory preventing the calculation. Therefore, I would like to change the constant array matrix into sparse matrix ...
3 votes
1 answer
307 views

Efficient memory usage while building a large sparse matrix

I am sure the following problem has been solved already, but I am unable to find any solution... Any help appreciated! So I am building a pretty huge matrix (or tensor, actually) using ...
1 vote
0 answers
69 views

Method for MinimumBandwidthOrdering [closed]

MinimumBandwidthOrdering[m, Method -> "RCMD"] What method is 'RCMD' in Mathematica? Reverse Cuthill-McKee, Reduced Canonical Matrix Diagram, Restricted Minimum Column Degree, other?
8 votes
2 answers
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$ ...
3 votes
3 answers
174 views

Insert a dynamic vector into a matrix

If I have the following dynamic vector Cs[NN_] := Table[{Sin[(2*i - 1) τ], Sin[(2*i - 1) τ]}, {i, 1, NN}] // Flatten The size of Cs depends on the integer ...
53 votes
2 answers
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 ...
2 votes
0 answers
68 views

Dot product of arrays that are members of the same list

Lets say I have a list of n arrays: n=3; list = Table[RandomInteger[{-10, 10}, {2, 2}], n]; I would like to calculate the matrix corresponding to: ...
2 votes
1 answer
127 views

How do I create a banded matrix using values from a given function [closed]

I would like to create a matrix were values of the function P make up the diagonals. I tried using the For loop but did not get it right. ...
4 votes
1 answer
247 views

Speeding Up Sparse Matrix Generalized Eigenvalues

I have a generalized eigenvalue problem $$ {\mathbf A}\vec v = \lambda {\mathbf B} \vec v $$ for which I am trying to find the smallest eigenvalue $\lambda$ and the associated eigenvector $\vec v$. ...
4 votes
1 answer
182 views

Memory leak when creating a SparseArray

Problem: I have a list e={u,v,w} and wish to construct a sparse matrix with entries {u[i],v[i]}->w[i]. Note that the same ...
2 votes
1 answer
129 views

Reconstruction on large sparse array

I'm struggling with a reconstruction of a large sparse array. What I'm trying to do is to rearrange a 2 dimensional array (respresenting a system matrix for a given system of equations) such that I ...
7 votes
4 answers
1k views

Implementation of MATLAB's "numgrid" function [closed]

I am looking for an implementation of MATLAB's numgrid function, in particular the "B" mode. For example, I want to get the matrix corresponding to the ...
4 votes
1 answer
594 views

How to RowReduce a sparse matrix?

I want to compute the reduced row echelon form of a sparse matrix, but RowReduce returns a dense matrix. Is there a build-in function that computes the reduced form ...
23 votes
3 answers
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 ...
1 vote
1 answer
84 views

Plotting multidimensional tables

I have a tridiagonal matrix created by ...
20 votes
1 answer
436 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 ...
2 votes
2 answers
550 views

How to handle a sparse array of lists

I have data in the form of a sparse array of lists. For example: ...
1 vote
0 answers
59 views

Erratic behavior retrieving large data (several tens of gigabytes) that has been serialized by Mathematica

Hardware: PC with 256GB RAM OS: Windows 10 Mathematica: Version 13.0.1 One of my projects has led to the creation of a SparseArray whose ByteCount is ~ 35GB in RAM. At the time of creation the ...
2 votes
1 answer
109 views

Define a function with sparsearray

I am trying to define a function using SparseArray, but the entries were defined before. How can I avoid this error? Code is: ...
1 vote
0 answers
33 views

Why does Sparsearray diagonalization by Krylov technique become slower for very large sizes?

Here is an example sparse matrix, taken from example Hamiltonian, which was a question I asked before in this forum. ...
2 votes
0 answers
29 views

Threshold on triangular SparseArray

I am confused by the behavior of Threshold on sparse UpperTringularize (and LowerTringularize...
3 votes
0 answers
76 views

Fastest Way to make rows and columns zero and corresponding (i,i) element 1 of a large Sparse Matrix

I have a 5552 by 5552 sparse matrix: ...
4 votes
3 answers
601 views

Generating signed permutation matrices

As most people (on here at least) know a permutation matrix is a square binary matrix that has exactly one entry of 1 in each row and each column and 0s elsewhere. For the $n \times n$ case there are $...

1
2 3 4 5
7