Find us on GitHub

Teaching basic lab skills
for research computing

Matrix Programming

Linear algebra lies at the heart of most scientific computations, so developers have been building and tuning libraries to do vector and matrix operations for sixty years. These libraries are frequently also used to work on other block data, such as images and grids; as a result, they have a bewildering variety of features, but repay close study with concise, high-performance code.

  • Array libraries like NumPy store data in rectangular blocks of uniform data type.
  • These libraries use a data-parallel programming model to apply one operation to many data elements.
  • You should (almost) never loop over the elements of a vector or matrix: let the library do it instead.
  • Use slicing to select and combine subsets of data.
  • And use library functions to do higher-level linear algebra operations rather than writing them yourself.
  1. Introduction
  2. Basic Operations
  3. Indexing
  4. Linear Algebra
  5. Recommendations