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
2 votes
3 answers
129 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 ...
user avatar
  • 1,163
1 vote
1 answer
69 views

Plotting multidimensional tables

I have a tridiagonal matrix created by ...
user avatar
  • 295
0 votes
0 answers
34 views

Trying to map SparseArray over a defined list, the SparseArray defined with 3 subvalues i want to map the 3rd. subValue(list) over the defined list

I have a SparseArray already defined as following ...
user avatar
1 vote
0 answers
50 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 ...
user avatar
  • 2,024
2 votes
1 answer
80 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: ...
user avatar
1 vote
0 answers
20 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. ...
user avatar
2 votes
0 answers
22 views

Threshold on triangular SparseArray

I am confused by the behavior of Threshold on sparse UpperTringularize (and LowerTringularize...
user avatar
3 votes
0 answers
68 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: ...
user avatar
4 votes
3 answers
230 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 $...
user avatar
  • 485
7 votes
0 answers
100 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 ...
user avatar
  • 71
0 votes
0 answers
62 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? ...
user avatar
2 votes
1 answer
56 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 ...
user avatar
  • 1,100
9 votes
2 answers
162 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 ...
user avatar
  • 1,624
7 votes
0 answers
51 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 ...
user avatar
  • 17.9k
0 votes
0 answers
25 views

Refer to entry of input matrix in SparseArray

The code ...
user avatar
2 votes
0 answers
96 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 ...
user avatar
4 votes
0 answers
72 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 ...
user avatar
  • 425
6 votes
2 answers
252 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 ...
user avatar
  • 141
1 vote
2 answers
83 views

How to dynamically define matrix with blocks in subdiagonals?

...
user avatar
  • 425
1 vote
1 answer
107 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 ...
user avatar
2 votes
0 answers
29 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 ...
user avatar
  • 611
2 votes
1 answer
223 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 ...
user avatar
  • 1,624
3 votes
1 answer
96 views

How to write correctly some arguments in SparseArray

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

Parallelizing construction of sparsearray

I'm constructing sparse arrays where blocks of each array are results of the integral defined in integralList ...
user avatar
1 vote
2 answers
115 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 ...
user avatar
0 votes
0 answers
47 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$ ...
user avatar
  • 912
1 vote
1 answer
45 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 ...
user avatar
  • 912
9 votes
1 answer
172 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 ...
user avatar
1 vote
0 answers
80 views

Fast definition of sparse tensor

I'm defining a sparse array through ...
user avatar
  • 459
1 vote
1 answer
81 views

Lowest Eigenvalue of a large sparse matrix without choking up the RAM (Corrected) [closed]

I am trying to find the lowest eigenvalue of a large sparse matrix of dimension N (=$3^n$, where n is number of particles in system ) using ...
user avatar
  • 902
3 votes
1 answer
114 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 ...
user avatar
  • 1,095
2 votes
0 answers
99 views

What is the fastest way to get the lowest eigenvalue and corresponding eigenstate in Mathematica?

I tried to use the Arnoldi method to get the smallest eigenvalue and corresponding eigenstate for large matrix. However, Arnoldi did not give me the desired result: ...
user avatar
  • 657
6 votes
1 answer
142 views

Efficient construction of a SparseArray from LIL (list of lists of column entries)

In Python scipy.sparse, there are methods to convert between CSR, CSC, LIL, DOK, etc. implementations of a sparse matrix. What is the most efficient way in Mathematica to construct a ...
user avatar
  • 1,095
4 votes
0 answers
122 views

Insufficient memory problem in Mathematica

I am trying to initialize a 48600 x 48600 packed array from a sparse matrix and a diagonal matrix in Mathematica 8. If S1 is a sparsearray of that size then and S2 is list of 48600 length, then I am ...
user avatar
4 votes
2 answers
119 views

How to efficiently upsample a greyscale image to generate a representative binary image

I want to create binary images by upsampling a series of greyscale images (192 x 144 resolution) by a factor of 10 with the new pixel values being a pseudorandom distribution of 0's & 1's based on ...
user avatar
  • 3,623
3 votes
2 answers
143 views

Creating a block matrix from arrays of blocks

I am trying to generate a matrix from square blocks. Effectively, I have a $n×n$ matrix polynomial $P(l)$, the $qth$ derivative of $P(l)$ with respect to $l$, which is denoted by $P^{(q)} (l)$, and a ...
user avatar
  • 41
5 votes
2 answers
201 views

Permute association key and generate a sparse array

Imagine having an Association Av = <|{1, 4, 2, 3} -> a, {2, 4, 2, 4} -> b|> It can be much longer. I am searching ...
user avatar
  • 15.7k
0 votes
1 answer
65 views

How can I define a function using ArrayFlatten without using SetDelayed?

I created a matrix F2 using SparseArray and ArrayFlatten as follows: ...
user avatar
0 votes
0 answers
61 views

Seeming inconsistencies with "Eigenfunction" [duplicate]

I am working on a problem which involves calculating the spectrum of a family of 2970x2970 Hermitian matrices. I have done similar things with Mathematica in the past, but this time there is an odd, ...
user avatar
  • 595
-1 votes
1 answer
62 views

Construct a matrix from blocks of matrices [closed]

I am trying to find eigen values of a matrix system where entries of the matrix are also matrix. This is how my matrix looks: $$ M=\begin{bmatrix} H[j,j] & T[j,j+1] & 0 &0 &....
user avatar
2 votes
2 answers
136 views

Elegant way to construct a matrix with symbolic entries

I would like to construct a matrix $G$ composed of block matrices $G^{(i)}$ as defined entry-wise below stacked vertically as $$G = \begin{bmatrix} G^{(1)} \\ G^{(2)} \\ \vdots \\ G^{(i)} \\ \vdots \\ ...
user avatar
  • 179
3 votes
1 answer
57 views

How do I pass indices to a function when constructing a SparseArray?

I am trying to speed up my Mathematica code, so instead of testing and calculating the same thing again and again I want to save the result in a SparseArray. The goal is to generate a matrix which I ...
user avatar
  • 1,005
0 votes
1 answer
108 views

Import and export a list of SparseArrays efficiently?

I have a list of integers dims and a list of SparseArrays bdrs (representing a chain complex ...
user avatar
  • 1,095
0 votes
0 answers
53 views

How to find the rank of a sparse-array list without memory leaks?

I have a very wide list of sparse arrays (I basically just used the numbers as an encoding mechanism for vectors of polynomials), and I want to find out whether they're linearly independent. How ...
user avatar
7 votes
1 answer
242 views

Efficiently populate sparse matrix with band structure

I'm trying to efficiently populate elements of a very large (2^20 x 2^20) symmetric matrix with 1s - luckily the matrix is very sparse, <0.1% filling. Further, the matrix has a very well defined ...
user avatar
9 votes
3 answers
272 views

Multiplying two complex SparseArray objects, yielding empty SparseArray crashes kernel

Problem: When I multiply together two sparse matrices that should give back the 0 matrix, where at least one element among the two is complex and at least one is not an exact number, the kernel ...
user avatar
  • 1,814
8 votes
1 answer
268 views

SparseArray to list of lists (column entries) efficiently?

Suppose we have a very big very sparse matrix, e.g.: ...
user avatar
  • 1,095
1 vote
0 answers
57 views

How to apply PolynomialMod to a SparseArray?

I have a list bdrs of SparseArrays, whose entries are polynomials in the variable t with ...
user avatar
  • 1,095
10 votes
2 answers
239 views

`Count` for `SparseArray`

Why does Count not work with SparseArrays, and is there any function I can use to replace it? What would be an efficient ...
user avatar
  • 459
7 votes
0 answers
127 views

Memory usage for smallest eigenvalues

I have a bunch of hermitian matrices which are huge (of order 2^17 x 2^17) but extremely sparse so that, when I build the matrices, the usage of RAM is low (say of order 1 GB or similar). The ...
user avatar

1
2 3 4 5 6