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
3 votes
1 answer
116 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 ...
Yilin Cheng's user avatar
2 votes
0 answers
66 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. ...
Lelouch's user avatar
  • 513
0 votes
0 answers
28 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 \...
user2757771's user avatar
1 vote
1 answer
31 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" ...
infernophys's user avatar
8 votes
1 answer
309 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): ...
BesselFunct's user avatar
5 votes
2 answers
192 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 ...
Facieod's user avatar
  • 175
6 votes
1 answer
105 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 ...
Gert's user avatar
  • 1,470
0 votes
2 answers
54 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$) ...
Facieod's user avatar
  • 175
9 votes
7 answers
772 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 ...
IntroductionToProbability's user avatar
4 votes
1 answer
147 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 ...
Albercoc's user avatar
  • 966
8 votes
1 answer
145 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 (...
Albercoc's user avatar
  • 966
6 votes
2 answers
267 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,<...
Albercoc's user avatar
  • 966
6 votes
1 answer
136 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: ...
thils's user avatar
  • 3,198
1 vote
0 answers
54 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?
Pezzin's user avatar
  • 53
5 votes
1 answer
131 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 ...
Kazim Ahmet Hasim's user avatar
3 votes
1 answer
201 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 ...
Philipp's user avatar
  • 115
2 votes
0 answers
64 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: ...
Gabriele Stevanato's user avatar
7 votes
1 answer
124 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 ...
Florentin Münch's user avatar
2 votes
1 answer
112 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. ...
Sam Rametse's user avatar
4 votes
1 answer
209 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$. ...
Guy's user avatar
  • 285
2 votes
1 answer
119 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 ...
Frida's user avatar
  • 45
6 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 ...
Yaroslav Bulatov's user avatar
3 votes
3 answers
169 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 ...
qahtah's user avatar
  • 1,329
1 vote
1 answer
83 views

Plotting multidimensional tables

I have a tridiagonal matrix created by ...
Shasa's user avatar
  • 801
1 vote
0 answers
57 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 ...
Todd Allen's user avatar
  • 2,114
2 votes
1 answer
100 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: ...
Jose Nuñez's user avatar
1 vote
0 answers
29 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. ...
Roopayan Ghosh's user avatar
2 votes
0 answers
27 views

Threshold on triangular SparseArray

I am confused by the behavior of Threshold on sparse UpperTringularize (and LowerTringularize...
Markus Roellig's user avatar
3 votes
0 answers
74 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: ...
S.B.MD.Khaja Moinuddin's user avatar
4 votes
3 answers
499 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 $...
1729taxi's user avatar
  • 747
8 votes
0 answers
171 views

Defining a SparseArray functions in Mathematica 13

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
  • 81
0 votes
0 answers
710 views

How to convert an SparseArray into a Matrix?

I have the following sparse array and I want to change it to a matrix. Could you please tell me how to do that? ...
Delaram Nematollahi's user avatar
2 votes
1 answer
112 views

How to create a 3D matrix from different blocks?

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,335
9 votes
2 answers
195 views

SparseArray Input

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,816
7 votes
0 answers
54 views

Is there a way to make SparseArray distinguish between background values of different precision that are numerically equal?

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
  • 21.9k
0 votes
0 answers
33 views

Refer to entry of input matrix in SparseArray

The code ...
user984949's user avatar
2 votes
0 answers
176 views

Building a Matrix as a piecewise-function of the indices without for loops [closed]

I'm very new to Mathematica and this site. I've read that building matrices with For loops is slow, and I have experienced this myself on the current project. I'm trying to wrap my head around ...
ignorantFool's user avatar
4 votes
0 answers
98 views

How to efficiently build a large sparse matrix and overloading a compiled function?

I would like to construct a large sparse matrix folding from rank-4 tensor given by the following: $\mathcal{L}_{1L}^{00}(i,j)=\mathcal{L}_{1L}^{00}(m_1,m_2;M_1,M_2)$ The indices of matrix $(i,j)$ are ...
Bob Lin's user avatar
  • 445
6 votes
2 answers
436 views

Speedup the production of a sparse symmetric matrix with a dense vector

The optimization of the production of a sparse symmetric matrix with a dense vector has existed for a long time. Someone once compared the matrix operations of Mathematica with MATLAB, and then came ...
sidy's user avatar
  • 141
1 vote
2 answers
130 views

How to dynamically define matrix with blocks in subdiagonals?

...
Bob Lin's user avatar
  • 445
1 vote
1 answer
155 views

Why does generating a list of elements for SparseArray crash the kernel?

I am trying to create a sparse matrix by the SparseArray command. For a set of index pairs $(i,j)$ I want to calculate the $A_{i,j}$ element and then use this ...
Kieran Mullen's user avatar
2 votes
0 answers
52 views

Implementing array with partial cyclic data?

I'd like to construct an array where some columns are cyclic. As an illustrative example, take Table[Mod[k, 2^i], {k, 2^10}, {i, 0, 10}] //Grid, where the vast ...
Trev's user avatar
  • 763
2 votes
1 answer
322 views

Diagonal matrix command in Mathematica

How to find the corresponding Mathematica commands for diagonal matrix operation in Matlab, e.g. AA=rand(3,3); Step 1.) finding the diagonal elements, and export ...
ABCDEMMM's user avatar
  • 1,816
3 votes
1 answer
126 views

How to write correctly some arguments in SparseArray

I am struggling to put an argument in SparseArray. Let's consider the following example ...
DGtrauko's user avatar
1 vote
0 answers
64 views

Parallelizing construction of sparsearray

I'm constructing sparse arrays where blocks of each array are results of the integral defined in integralList ...
tomeq's user avatar
  • 63
1 vote
2 answers
177 views

Improving large array manipulation

I am doing an iterative program, which uses large arrays/vectors and where the output of one round is used as an input for the next steps but works slowly when dimensions are bigger. In brief, we ...
DGtrauko's user avatar
0 votes
0 answers
83 views

sparse matrix multiplication

Say I have a sparse matrix $M$ with $\sim 50.000 .000$ non zero elements. What is the fastest way to make operations such as : $$M^k X$$ where $X$ is a given vector. Is the operation $MX$ ...
DarkBulle's user avatar
  • 964
1 vote
1 answer
68 views

Fastest way to convert two associations into a sparse matrix

I have two association $N$ and $C$ $N$ has this form : $N=<|x_1\rightarrow \{x_{1,1},...x_{1,p_1}\},x_2\rightarrow \{x_{2,1},...x_{2,p_2}\}...,x_D\rightarrow \{x_{D1},...x_{Dp_D}\} |>$ $C$ has ...
DarkBulle's user avatar
  • 964
9 votes
1 answer
194 views

Efficiently populate a Sparsearray for a set of rules for a constrained basis

I want to populate quite a large SparseArray(10^6 x10^6) efficiently. It is basically a spin system Hamiltonian with a constrained Hilbert space. Unlike the examples I have looked at in this forum ...
Roopayan Ghosh's user avatar
1 vote
0 answers
88 views

Fast definition of sparse tensor

I'm defining a sparse array through ...
Daniel's user avatar
  • 499

1
2 3 4 5
7