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

learn more… | top users | synonyms

3
votes
1answer
85 views

How can I efficiently ArrayFlatten a matrix of sparse matrices?

I have a matrix of sparse matrices that I want to convert to a sparse block matrix. So, basically I want what ArrayFlatten does, except that I want the output to be ...
1
vote
1answer
39 views

Conditions in SparseArray

I got confused by {i_, j_} /; in the following code. I didn't see an explanation in the SparseArray documentation. Can anyone ...
0
votes
1answer
21 views

Interactively Manipulate SparseArrays or Lists

I'd love to use SparseArrayor List to group a set of parameters together in a function. ...
5
votes
0answers
65 views

Possible bug: SparseArray Part assignment loses default value?

This sure looks like a bug to me (Mathematica 10.0.0, MacOS): ...
7
votes
1answer
106 views

Building sparse array from packed arrays

Suppose I have two large packed arrays a and b, that respectively contain the position of the elements of a square matrix (i.e. ...
1
vote
1answer
50 views

Devising a sparse array rule

Suppose I have a matrix A={{1, 2}, {3, 4}} that defines the positions of non-zero values in a sparse array: ...
2
votes
2answers
105 views

Create a matrix of matrices using Band and ArrayFlatten [duplicate]

I can easily write a simple Band matrix using: SparseArray[{Band[{2, 1}] -> a}, {Dim, Dim}] where a is a number. Now, I ...
0
votes
1answer
45 views

What's wrong with my rule? [duplicate]

Consider a simple code to form a SparseArray: Q = 5; a = Table[i, {i, Q}]; SparseArray[{{j_} /; j > 2 -> a[[j]]}, {Q}] Part::pspec: Part specification j ...
3
votes
1answer
294 views

Transforming a huge rectangular table to Sparse Array

I am interested in the most efficient way to transform a huge rectangular array to a sparse array structure. Consider a numeric rectangular table that is rather sparse, with zero positions being set ...
3
votes
1answer
132 views

Are there any more time-efficient ways to solve a matrix equation than with SparseArray and LinearSolve?

I am trying to solve a matrix equation, with the matrix being tridiagonal. The problem I am having is that a message keeps appearing that I don't have enough memory. Here is the code: ...
2
votes
1answer
132 views

How to handle a sparse array of lists

I have data in the form of a sparse array of lists. For example: ...
5
votes
0answers
100 views

SparseArray internal structure [duplicate]

According to the documentation: SparseArray is treated as a raw object by functions like AtomQ and for purposes of pattern ...
11
votes
2answers
197 views

Bug with SparseArray selector in Pick

I have created a notebook with two cells. This is the content of the first: ...
4
votes
2answers
114 views

Values (or positions) of array row elements within a specified number of positions from target value

I have the need to collect values from the rows of rectangular arrays of arbitrary precision integers, given a target element value and allowed "distance" (positions +/- within the row from found ...
1
vote
2answers
118 views

Manipulating sparse array elements

Suppose I have two sparse arrays ...
6
votes
1answer
347 views

Find the eigenvector associated with the smallest eigenvalue, not smallest in magnitude

I am trying to find the eigenvector of a $20000 \times 20000$ sparse matrix associated with the smallest eigenvalue. I realized that the smallest eigenvalue might be negative; for example, if the ...
4
votes
3answers
332 views

Finding elements from a sparse matrix

I am dealing sparse matrices of very large dimensions. I need to locate the positive and negative elements of the matrices and make lists of their corresponding positions. Of course I can write a ...
0
votes
0answers
59 views

Is there a faster way to do Normal[SparseArray[{{1,1,1}→1.2, {1,1,2}→20.2, …, {m,n,p}→0.3}]]?

I have a list of the form {{1,1,1}→1.2, {1,1,2}→20.2, ..., {m,n,p}→0.3} and I want to create an $m \times n \times p$ array, $A$, where the value of $A[[i,j,k]]$ is ...
0
votes
0answers
46 views

Addition of sparse array objects [duplicate]

I have been having some trouble with the addition of large (but very sparse) matrices using SparseArray. Here is the simplest example to illustrate the issue. First, I will define diagonal matrices ...
10
votes
1answer
174 views

Sporadic bugs in multidimensional SparseArray objects

Udate This SparseArray[] bug is (apparently) fixed on version 10.0 ...
2
votes
1answer
103 views

Product of non-zero elements in sparse array

How can I multiply the non-zero elements of a SparseArray? Example: ...
1
vote
1answer
80 views

Specify positions in a SparseArray using patterns with functions

I spent some time trying to figure out what was what was making so slow the calculation of the following array(actually this is only a SUPERsimple toy model): Input to the array: ...
3
votes
0answers
65 views

Efficient storage of Kronecker sum of circulant matrices+diagonal matrix

I have a square matrix of the form $$M=D+\overset{N}{\underset{n=1}\bigoplus}R_n,$$ where $R_n$ are circulant matrices, $D$ is a diagonal matrix and $\oplus$ is Kronecker sum. Its size is quite big, ...
2
votes
1answer
94 views

Opposite function to Normal

Is there any function opposite to Normal? For example, let as say that I have an SparseMatrix A, then, let as say that for convenience for a certain operation like Packing, I convert it into an Array ...
4
votes
2answers
141 views

Upsampling matrix by inserting zeros inbetween elements

I want to essentially take an image with $n \times n$ pixels and expand it into a sparse array, spacing out the pixels by a factor $2$ or $3$. Each pixel in the input image occupies one of the corners ...
6
votes
2answers
146 views

Additive SparseArray Assembly

The goal is to assemble a SparseArray in an additive fashion. Let us assume we have a large List of indices (some will be ...
1
vote
3answers
98 views

ArrayRules for a ragged list

Let there be a sample list as , l = {a, {{b, c}}, {d, e}, {f}, {{g, {y}, u, h}, {{{{k, j}}}}},k, {{{{q}, {w}, {r}, {x}}}}}; ArrayRules[l] ArrayRules::rect: ...
2
votes
1answer
156 views

How to create a SparseArray satisfying multiple conditions on Parts and Elements of a Matrix?

I have a matrix m1 of size $3 \times 19$. Rows $1$, $2$ and $3$ represent $3$ different groups, and columns represent $4$ different blocks: block1 - columns $1$, ...
-3
votes
1answer
117 views

the way to save multidimensional array in text file [closed]

I have an array which is defined as a table, e.g. g = Table[ cos[l1*3.]*sqrt[l2*1.]*l3 + l1*1 , {l1, 0, 3}, {l2, 0, 3}, {l3, 0, 3}]; then, I need to save it in ...
4
votes
3answers
243 views

SparseArray row operations

Given a large (very) sparse matrix, A, how can I efficiently "operate" on only the nonzeros in a given row? For example: For each row in A, generate a list of column indices that have a magnitude ...
2
votes
0answers
75 views

Det and MatrixRank freezes on SparseArray with nonzero default value

Why does the following simple code never come to an end (at least with version 8) n = 5; mat = SparseArray[{i_, i_} -> 1, {n, n}, -1/(n - 1)]; MatrixRank[mat] ...
3
votes
1answer
120 views

Assigning Sequence to Part of a SparseArray (bug?)

Part ▪ You can make an assignment like t[[spec]]=value to modify any part or sequence of parts in an expression. ▪ If ...
0
votes
1answer
143 views

Is it in general faster to get the eigenvectors and eigenvalues of a dense array rather than a sparse array?

I always thought that things in general go faster when working with sparse array but, I got this: Eigenvalues::arhm: Because finding 144 out of the 144 ...
5
votes
1answer
73 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 100.000.000 by 10 element SparseArray. And fill the two position 1/1 and ...
1
vote
0answers
40 views

How to estimate system recource usage of a SparseArray? [duplicate]

Build a 100.000.000 by 10 element SparsArray. Fill position 1/1 and 100.000.000/10 with a value 999.999.999.999.999. ...
2
votes
1answer
177 views

How to combine SparseArray and If

Because I am dealing with huge matrixes, my computer can not handle it, because of the memory. But, in my matrix, a very small percentage of the elements are non-zero. So I should use SparseArray as ...
1
vote
1answer
207 views

How to store a SparseArray? [duplicate]

How to Export/Write a SparseArray? How to Import/Read a SparseArray? Is it always stored as a normal array? How can it be stored in a dense form? Is a numerical SparseArray different to Export/Import ...
1
vote
3answers
257 views

Dynamically filling matrix with a[[n,m]] = 1/a[[m,n]]

I'm building a square matrix, with 1s on the diagonal and elements in U the inverse of elements in L, which are random integers drawn from the sequence 1, ..., 9. Given the nature of the problem I ...
6
votes
0answers
160 views

Calculating the rank of a huge sparse array

By virtue of the suggestion in my previous question, I constructed the sparse matrix whose size is $518400 \times 86400$, mostly filled with $0$ and $\pm 1$. Now I want to calculate its rank. Since ...
14
votes
6answers
574 views

Matrix Rotation

If I have a matrix of any size, say $\begin{pmatrix} 72 & 32 & 64 \\ 18 & 8 & 16 \\ 63 & 28 & 56 \\ \end{pmatrix}$ $\begin{pmatrix} 72 & 32 \\ 18 & 8 \\ 63 ...
5
votes
1answer
149 views

Why is Flattening a CoefficientArray so slow?

I have a vector of $n$ degree $n$ polynomials in $(x,y,z)$, each of whose coefficients is an inhomogenous linear expression in $3 n^2$ variables. I want to write down the linear equations in these $3 ...
3
votes
1answer
309 views

How to get the determinant and inverse of a large sparse symmetric matrix?

For example, the following is a $12\times 12$ symmetric matrix. Det and Inverse take too much time and don't even work on my ...
9
votes
2answers
299 views

Speed up 4D matrix/array generation

I have to fill a 4D array, whose entries are $\mathrm{sinc}\left[j(a-b)^2+j(c-d)^2-\phi\right]$ for a fixed value of $\phi$ (normally -15) and a fixed value of $j$ (normally about 0.00005). The way ...
5
votes
1answer
182 views

Summing tensors in mathematica

How do I perform the following summation in mathematica? \begin{equation} \Sigma_{m=1}^5 e_{ijklm}A^{mn} \end{equation} I have the $e_{ijklm}$ tensor of rank 5 in 5 dimension as a array and $A^{mn}$ ...
1
vote
1answer
491 views

Import Excel sheet into 3D array?

I have an excel spreadsheet that I would like to plot in a 3D graph using mathematica. The X and Y values are the location of the cell, and the Z value is the number of the scale. How can I import ...
6
votes
1answer
226 views

How to create a large sparse block matrix

I need to generate a very large sparse block matrix, with blocks consisting only of ones along the diagonal. I have tried several ways of doing this, but I seem to always run out of memory. The ...
14
votes
1answer
282 views

Adding three integer sparse matrices is very slow. Adding only two is fast

Adding more than two sparse matrices in one step in Mathematica 9 is very slow (in fact I couldn't even wait for it to finish). Here's an example. Let's generate a large sparse matrix: ...
5
votes
2answers
259 views

How to interpret the FullForm of a SparseArray?

SparseArrays are atomic objects, but they do have a FullForm which reveals information about them. What is the meaning of the ...
10
votes
1answer
1k views

How to work around Mathematica hanging when showing a large SparseArray?

Note: This is fixed in 9.0.1. In Mathematica 9, if I display any large SparseArray object in the default way (which looks something like ...
5
votes
1answer
178 views

What's wrong with this code to create a matrix?

Here is my code: ...