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
5 votes
1 answer
134 views

Say I have this very sparse vector of gigantic size: ...
Henrik Schumacher's user avatar
3 votes
1 answer
97 views

BinCounts sometimes outputs data as SparseArray, and sometimes Normal. This does not depend ...
lesobrod's user avatar
  • 2,590
0 votes
2 answers
163 views

I want to create a large sparse matrix by given 2 matrices with dimensions of $m\times m$ and $n\times n$. It will not be $6\times 6$ as in the picture, I only tried to give a simple example. I do not ...
merts's user avatar
  • 95
4 votes
1 answer
280 views

People say that mathematica is not as good as matlab for nunmerics. For my specific use case, I am trying to solve differential equations with the MatrixExp method ...
Luca's user avatar
  • 434
1 vote
0 answers
130 views

My question is related to my issue from yesterday (Initializing very large matrices). It was recommended to use SparseArray to initialize large matrices efficiently....
Birgit1287's user avatar
3 votes
2 answers
191 views

Let's say I have a "small" SparseArray of any size, in the example $2\times2$ ...
rhermans's user avatar
  • 37.7k
3 votes
1 answer
151 views

I discovered a difference between version 12.0 and version 14.0 in how they handle SparseArray within the Table function. For ...
sidy's user avatar
  • 33
0 votes
0 answers
134 views

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 ...
Kaio's user avatar
  • 85
3 votes
1 answer
255 views

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,...
coussin's user avatar
  • 391
6 votes
1 answer
80 views

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 ...
BioPhysicist's user avatar
  • 1,156
4 votes
2 answers
187 views

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 $\...
Matteo's user avatar
  • 315
6 votes
1 answer
197 views

Here is a snippet I use to dynamically define a bunch of functions f[i][x_]: ...
jrekier's user avatar
  • 525
7 votes
3 answers
283 views

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 ...
David G. Stork's user avatar
3 votes
2 answers
260 views

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 \...
Shasa's user avatar
  • 1,085
5 votes
2 answers
299 views

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 ...
coussin's user avatar
  • 391
1 vote
1 answer
275 views

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 ...
Yilin Cheng's user avatar
2 votes
0 answers
91 views

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. ...
Lelouch's user avatar
  • 555
0 votes
0 answers
118 views

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 \...
user2757771's user avatar
1 vote
1 answer
110 views

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" ...
infernophys's user avatar
8 votes
1 answer
370 views

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): ...
BesselFunct's user avatar
5 votes
2 answers
235 views

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 ...
Facieod's user avatar
  • 175
6 votes
1 answer
164 views

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 ...
Gert's user avatar
  • 1,783
0 votes
2 answers
107 views

I have a large sparse array A with dimensions $m \times n \times q $. I also have two transformation matrices, B ($n \times n$) ...
Facieod's user avatar
  • 175
10 votes
7 answers
963 views

I would like to make a rectangular array of 1 and 0 with continuous columns of 1. We are ...
IntroductionToProbability's user avatar
5 votes
1 answer
212 views

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 ...
Albercoc's user avatar
  • 1,122
8 votes
1 answer
365 views

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 (...
Albercoc's user avatar
  • 1,122
6 votes
2 answers
344 views

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,<...
Albercoc's user avatar
  • 1,122
6 votes
1 answer
236 views

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: ...
thils's user avatar
  • 3,303
2 votes
0 answers
107 views

MinimumBandwidthOrdering[m, Method -> "RCMD"] What method is 'RCMD' in Mathematica? Reverse Cuthill-McKee, Reduced Canonical Matrix Diagram, Restricted Minimum Column Degree, other?
Pezzin's user avatar
  • 63
5 votes
1 answer
212 views

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 ...
Kazim Ahmet Hasim's user avatar
3 votes
1 answer
544 views

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 ...
Philipp Strasberg's user avatar
2 votes
0 answers
104 views

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: ...
Gabriele Stevanato's user avatar
10 votes
1 answer
263 views

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 ...
Florentin Münch's user avatar
2 votes
1 answer
198 views

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. ...
Sam Rametse's user avatar
4 votes
1 answer
421 views

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$. ...
Guy's user avatar
  • 285
2 votes
1 answer
184 views

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 ...
Frida's user avatar
  • 45
7 votes
4 answers
1k views

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 ...
Yaroslav Bulatov's user avatar
3 votes
3 answers
219 views

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 ...
qahtah's user avatar
  • 1,436
1 vote
1 answer
117 views

I have a tridiagonal matrix created by ...
Shasa's user avatar
  • 1,085
1 vote
0 answers
103 views

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 ...
Todd Allen's user avatar
  • 2,274
2 votes
1 answer
155 views

I am trying to define a function using SparseArray, but the entries were defined before. How can I avoid this error? Code is: ...
Jose Nuñez's user avatar
1 vote
0 answers
67 views

Here is an example sparse matrix, taken from example Hamiltonian, which was a question I asked before in this forum. ...
Roopayan Ghosh's user avatar
2 votes
0 answers
51 views

I am confused by the behavior of Threshold on sparse UpperTringularize (and LowerTringularize...
Markus Roellig's user avatar
4 votes
3 answers
786 views

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 $...
1729taxi's user avatar
  • 826
10 votes
0 answers
255 views

I am defining a sparse array as a function of argument x, i.e. f[x_] = SparseArray[{1->x}, {3}] In Mathematica 12 this works perfectly, I can pass arguments and ...
Alik's user avatar
  • 101
2 votes
1 answer
174 views

I would like to generate a $3D$ matrix of dimension $(n1\times n1\times n1)$ compose of $216$ matrix blocks $(n2\times n2\times n2)$. All 216 matrix blocks are subdivided into 4 groups, each one with ...
SAC's user avatar
  • 1,343
9 votes
2 answers
254 views

How to create a SparseArray without using lists of rule in MMA? In MMA we can define a SparseArray using lists of rule ...
ABCDEMMM's user avatar
  • 1,884
7 votes
0 answers
79 views

To illustrate what I mean, consider the following: SparseArray[{{1} -> 1, {5} -> 1.}, Automatic, 0] // Normal {1, 0, 0, 0, 1.} As you can see, the ...
Sjoerd Smit's user avatar
  • 25.7k
0 votes
0 answers
57 views

The code ...
user984949's user avatar

1
2 3 4 5
7