I would like to know whether there is a general method (and, if so, which one) to create a sparse matrix from a dense matrix. I know a sparse matrix simply does not include the zero entries, but since their allocation in the matrix can be very diverse, I am wondering whether that derivation from dense to sparse can be somehow automatized......
2026-04-04 09:33:29.1775295209
Creating a sparse matrix from a dense matrix
1.3k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
There are 1 best solutions below
Related Questions in MATRICES
- How to prove the following equality with matrix norm?
- I don't understand this $\left(\left[T\right]^B_C\right)^{-1}=\left[T^{-1}\right]^C_B$
- Powers of a simple matrix and Catalan numbers
- Gradient of Cost Function To Find Matrix Factorization
- Particular commutator matrix is strictly lower triangular, or at least annihilates last base vector
- Inverse of a triangular-by-block $3 \times 3$ matrix
- Form square matrix out of a non square matrix to calculate determinant
- Extending a linear action to monomials of higher degree
- Eiegenspectrum on subtracting a diagonal matrix
- For a $G$ a finite subgroup of $\mathbb{GL}_2(\mathbb{R})$ of rank $3$, show that $f^2 = \textrm{Id}$ for all $f \in G$
Related Questions in TERMINOLOGY
- The equivalent of 'quantum numbers' for a mathematical problem
- Does approximation usually exclude equality?
- Forgot the name of a common theorem in calculus
- Name of some projection of sphere onto $\mathbb{R}^2$
- What is $x=5$ called??
- Is there a name for this operation? $f(a, b) = a + (1 - a)b$
- When people say "an algebra" do they always mean "an algebra over a field"?
- What is the term for "in one $n$-space"?
- The product of disjoint cycles
- What about the 'geometry' in 'geometric progression'?
Related Questions in COMPUTER-SCIENCE
- What is (mathematically) minimal computer architecture to run any software
- Simultaneously multiple copies of each of a set of substrings of a string.
- Ackermann Function for $(2,n)$
- Algorithm for diophantine equation
- transforming sigma notation into harmonic series. CLRS A.1-2
- Show that if f(n) is O(g(n) and d(n) is O(h(n)), then f(n) + d(n) is O(g(n) + h(n))
- Show that $2^{n+1}$ is $O(2^n)$
- If true, prove (01+0)*0 = 0(10+0)*, else provide a counter example.
- Minimum number of edges that have to be removed in a graph to make it acyclic
- Mathematics for Computer Science, Problem 2.6. WOP
Related Questions in TRANSFORMATION
- $\int \ x\sqrt{1-x^2}\,dx$, by the substitution $x= \cos t$
- Functions on $\mathbb{R}^n$ commuting with orthogonal transformations
- How do you prove that an image preserving barycentric coordinates w.r.t two triangles is an affine transformation?
- Non-logarithmic bijective function from $\mathbb{R}^+$ into $\mathbb{R}$
- Where does this "magical" transformatiom come from?
- Calculate the convolution: $\frac{\sin(4t)}{\pi t}*( \cos(t)+\cos(6t) )$ using Fourier transform
- Find all $x \in\mathbb R^4$ that are mapped into the zero vector by the transformation $x \mapsto Ax$
- Linear transformation $f (ax+by)=$?
- Is a conformal transformation also a general coordinate transformation?
- Infinite dimensional analysis
Trending Questions
- Induction on the number of equations
- How to convince a math teacher of this simple and obvious fact?
- Find $E[XY|Y+Z=1 ]$
- Refuting the Anti-Cantor Cranks
- What are imaginary numbers?
- Determine the adjoint of $\tilde Q(x)$ for $\tilde Q(x)u:=(Qu)(x)$ where $Q:U→L^2(Ω,ℝ^d$ is a Hilbert-Schmidt operator and $U$ is a Hilbert space
- Why does this innovative method of subtraction from a third grader always work?
- How do we know that the number $1$ is not equal to the number $-1$?
- What are the Implications of having VΩ as a model for a theory?
- Defining a Galois Field based on primitive element versus polynomial?
- Can't find the relationship between two columns of numbers. Please Help
- Is computer science a branch of mathematics?
- Is there a bijection of $\mathbb{R}^n$ with itself such that the forward map is connected but the inverse is not?
- Identification of a quadrilateral as a trapezoid, rectangle, or square
- Generator of inertia group in function field extension
Popular # Hahtags
second-order-logic
numerical-methods
puzzle
logic
probability
number-theory
winding-number
real-analysis
integration
calculus
complex-analysis
sequences-and-series
proof-writing
set-theory
functions
homotopy-theory
elementary-number-theory
ordinary-differential-equations
circles
derivatives
game-theory
definite-integrals
elementary-set-theory
limits
multivariable-calculus
geometry
algebraic-number-theory
proof-verification
partial-derivative
algebra-precalculus
Popular Questions
- What is the integral of 1/x?
- How many squares actually ARE in this picture? Is this a trick question with no right answer?
- Is a matrix multiplied with its transpose something special?
- What is the difference between independent and mutually exclusive events?
- Visually stunning math concepts which are easy to explain
- taylor series of $\ln(1+x)$?
- How to tell if a set of vectors spans a space?
- Calculus question taking derivative to find horizontal tangent line
- How to determine if a function is one-to-one?
- Determine if vectors are linearly independent
- What does it mean to have a determinant equal to zero?
- Is this Batman equation for real?
- How to find perpendicular vector to another vector?
- How to find mean and median from histogram
- How many sides does a circle have?
Somewhat longer comment:
Some problems lead naturally to sparse matrices, e.g., PDE discretizations using finite difference/volume/element methods, some Markov chains (when, e.g., you know a priori that a given state is related with a nonzero probability to a small number of other states) like in PageRank, etc.
The first question to answer is if it is really worth trying to convert a dense matrix to a sparse one and why? Is it to make the storage more efficient (in terms of the number of stored bytes), to use algorithms which benefit from the sparse structure, or...?
Note that just having a lot of zeros in your matrix does not mean it makes sense to convert it to a sparse one. While the dense matrix is usually stored in the form of a single array of numbers (with some sort of two-index access to it), sparse matrices, usually storing only the nonzero entries, need additional information about the distribution of the entries in the matrix (their "coordinates"). This additional information does represent an unnegligible storage overhead (in particular when the matrix is not so sparse). In addition, access to matrix entries involves indirect addressing and is not generally very "cache friendly" as in the case of dense matrices. Traditionally, a matrix is considered sparse if there the number of entries in rows/columns remain bounded by a constant independently of the size of the matrix (this is the when solving discretized PDEs). If, e.g., just half of the matrix entries are zeros, certainly it does not make sense to consider it as sparse.
Algorithms for sparse matrices are normally more complicated than their dense counterparts. One must pay attention, e.g., when factorizing the matrix, to the ordering and fill-in issues, which might destroy the sparsity of the factors and in fact make the use of sparse structures useless.
To the question: Yes, it is of course possible to convert a dense matrix to a sparse one (consider, e.g., the function
sparsein Matlab). For example, the CSR format (essentially the Yale one) can be created by traversing the rows of the dense matrix and filling sequentially the related arrays of the CSR structure. With the zero-based indexing, this can go as follows:$$ \begin{split} &\text{Input: $A\in\mathrm{R}^{m\times n}$}\\ &\text{Output: $RP=[0]$ (row pointers), $CI=[\;]$ (column indices), $VAL=[\;]$ (values)}\\ &PTR\gets 0\\ &\text{for $i=0,\ldots,m-1$}\\ &~~~~~~\text{for $j=0,\ldots,n-1$}\\ &~~~~~~~~~~~~\text{if $A(i,j)\neq0$ then}\\ &~~~~~~~~~~~~~~~~~~CI.\text{append}(j)\\ &~~~~~~~~~~~~~~~~~~VAL.\text{append}(A(i,j)\\ &~~~~~~~~~~~~~~~~~~PTR\gets PTR+1\\ &~~~~~~RP.\text{append}(PTR)\\ \end{split} $$
Nevertheless, it makes more sense to create a sparse matrix directly instead of storing it as a dense one in the first place.