What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
A SciPy CSR matrix stores a sparse two-dimensional array row by row: one array holds the nonzero values, another holds their column positions, and a third marks each row’s boundaries. This layout makes CSR a strong choice for row-based work and matrix-vector multiplication, but a poor fit for frequent column slicing or changes to which entries are stored.
What is a CSR matrix?
CSR means Compressed Sparse Row. It stores a matrix without allocating a value for every position: each row’s stored values and column indices occupy a contiguous segment of arrays. This is useful when most positions are zero and your computations can operate on the stored entries.
In SciPy, scipy.sparse.csr_matrix is the matrix-class interface for this format. The sparse overview also documents sparse arrays; the distinction matters because a sparse array is an array interface, while a sparse matrix follows matrix-specific behavior. See SciPy’s CSR matrix reference and sparse arrays overview.
Free tools Windows power users keep installed
One-click scans. No signup required.
How CSR’s three arrays work
A CSR object’s core representation consists of data, indices, and indptr:
#1 Best Overall
- Fundamental, two-line calculator that combines statistics and advanced scientific functions for high school math and science
- Two-line display shows the entry and calculated result at the same time for easy understanding of the calculation
- Fraction features, conversions, and basic scientific and trigonometric functions
- Solar and battery powered
- Approved for use on SAT, ACT and AP exams
datacontains the stored values.indicescontains the column index for each stored value.indptrmarks the start and end positions of each row’s segment in the first two arrays.
For row i, its column indices are indices[indptr[i]:indptr[i+1]], and the matching values are data[indptr[i]:indptr[i+1]]. The pair at a given position in indices and data identifies a stored matrix entry. The final value in indptr marks the end of the stored entries.
For example, if indptr is [0, 2, 3], row 0 uses entries 0 and 1, while row 1 uses entry 2. The number of stored entries is available as nnz. It counts explicitly stored zeros too, so it is not necessarily the count of mathematically nonzero values.
How to create a CSR matrix
Choose a constructor based on the data you already have. The following examples use the matrix interface named in the title.
Rank #2
- View multiple calculations at the same time: Compare results and explore patterns on-screen with the MultiView display that supports up to four lines
- See math exactly as it appears in textbooks: Display math expressions, symbols and stacked fractions exactly the way they appear in textbooks — no need to adapt to a technical syntax; provides quick access to frequently used functions
- Scientific notation output: View scientific notation with the proper superscripted exponents and see the output in scientific notation
- Explore (x,y) table of values: Students can easily explore an (x,y) table of values for a given function automatically or by entering specific x values
- The TI-30XS MultiView scientific calculator is ideal for general math, Pre-Algebra, Algebra 1 and 2, Geometry, Statistics, general science, Biology and Chemistry
Convert a dense array or another sparse object
import numpy as np
from scipy.sparse import csr_matrix
dense = np.array([[0, 4, 0], [2, 0, 5]])
A = csr_matrix(dense)
You can also pass another sparse matrix or sparse array to csr_matrix to convert it to CSR.
Build from coordinate triples
When your input is a list of row positions, column positions, and values, use the coordinate constructor. Specify the shape when trailing rows or columns may have no stored entries.
from scipy.sparse import csr_matrix
row = [0, 0, 1]
col = [0, 2, 1]
data = [3, 4, 5]
A = csr_matrix((data, (row, col)), shape=(2, 3))
The corresponding entries are placed at (row[k], col[k]) with value data[k]. If the same coordinate appears more than once, SciPy sums those values; for example, duplicate values 1 and 8 at (0, 0) produce 9.
Rank #3
- 10-digit display; for general math, pre-algebra, algebra 1 and 2, trigonometry and biology
- Performs trigonometric functions, logarithms, roots, powers, reciprocals, and factorials
- Also add, subtract, multiply and divide fractions; 1-variable statistics (mean / standard deviation)
- Conversions: fractions/decimals, degrees/radians/grads, DMS/decimal/degrees, and polar/rectangular
- Battery-powered; includes slide case
Construct directly from CSR arrays
If you already have row-compressed storage, pass the three arrays in CSR order:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11from scipy.sparse import csr_matrix
values = [3, 4, 5]
column_indices = [0, 2, 1]
row_pointers = [0, 2, 3]
A = csr_matrix((values, column_indices, row_pointers), shape=(2, 3))
The shape is optional for this form; when omitted, SciPy infers dimensions from the index arrays. Providing it explicitly makes the intended dimensions clear, especially when the last rows or columns contain no stored entries.
Create an empty matrix
from scipy.sparse import csr_matrix
A = csr_matrix((4, 6), dtype=float)
This creates a 4-by-6 matrix with no stored entries.
Rank #4
- Scientific Calculator with Graphic Function: All-in-one scientific and graphing calculator. Supports plotting functions, analyzing graphs, and solving complex equations. Displays graphs and formulas simultaneously for clear visualization. Ideal for algebra, calculus, and exam prep.
- Compact and Comfortable Design: This scientific and graphing calculator sized at 7 x 3.3 inches for a balanced and ergonomic feel. Fits easily in one hand or on a desk without taking up space. Ideal for long study sessions, test environments, and everyday academic or professional use; smooth button layout supports efficient input and navigation.
- Multiple Modes and 360+ Functions: Includes angle measurement, calculation, and display modes for flexible use across subjects. This scientific and graphing calculator supports over 360 functions such as fractions, complex numbers, statistics, linear regression, standard deviation, and variable solving. Ideal for mastering algebra, geometry, trigonometry, and advanced math applications.
- Durable and Portable Design: Built with an anti-drop body that resists everyday impacts for long-term use. This scientific and graphing calculator is lightweight and slim for easy carrying in a backpack or pocket that includes a protective case to guard the screen and buttons during travel or storage.
- If you cannot turn on the calculator, please press the reset button on the back! If you have any further problems, we offer a limited warranty of 365 days. Please contact us and we will give you an answer within 24 hours.
Building data efficiently
For data supplied as coordinate and value arrays, SciPy recommends COO as a construction format. DOK and LIL are also useful when constructing data or changing the sparsity structure. Convert to CSR when the structure is ready for row-oriented computation.
For incremental row-by-row construction, append each row’s column indices and values, then record the cumulative number of entries in indptr after every row. Each new pointer marks where the next row begins; the last pointer marks the total number of stored entries. This is the bookkeeping that turns accumulated row data into valid CSR storage.
Conversions among CSR, CSC, and COO are documented as linear-time. See SciPy’s sparse format overview for construction-format guidance and conversion details.
Best Value
- Natural Textbook Display presents formulas and results exactly as written in textbooks for intuitive learning.
What CSR is good at—and where it struggles
Pick a sparse format around the operations you perform most often, not just the way your input arrives.
| Format | Best fit | Trade-off |
|---|---|---|
| CSR | Row slicing, sparse arithmetic, and matrix-vector products | Column slicing is slow; changing the sparsity structure is expensive |
| CSC | Column slicing and column-oriented workloads | Row slicing is slow |
| COO | Construction from coordinate and value arrays | Convert to an operation-oriented format when appropriate |
| LIL or DOK | Building a matrix or changing which entries are stored | Choose another format for workloads better served by row- or column-compressed storage |
CSR supports sparse arithmetic, including addition, subtraction, multiplication, division, and matrix power. For a column-oriented workload, SciPy identifies CSC as the natural alternative: it provides efficient column slicing, while row slicing is slow. The CSC matrix reference describes that trade-off.
Use sparse operations deliberately
For matrix-vector multiplication, use the @ operator:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →result = A @ vector
A sparse result or operation should not be assumed to behave like a dense NumPy array. SciPy cautions against applying NumPy functions directly to sparse arrays without checking for a SciPy implementation or deliberately converting to dense. Densifying can allocate storage for every matrix position, including those represented sparsely before conversion.
Account for SciPy’s sparse API transition
SciPy’s csr_matrix reference warns that the project is shifting from a sparse matrix interface to a sparse array interface and expects to deprecate the matrix interface in the next few releases. The documentation does not establish a specific deprecation date. When maintaining code, consult SciPy’s current migration guidance and check how downstream libraries handle sparse arrays before changing an established matrix-based workflow.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

