Skip to content
pentapy: A Python toolbox for pentadiagonal linear systems
Python TeX
Branch: master
Clone or download
Latest commit 2f848ae Oct 9, 2019

Welcome to pentapy

status DOI PyPI version Build Status Build status Coverage Status Documentation Status Code style: black


pentapy is a toolbox to deal with pentadiagonal matrices in Python.

Pentadiagonal linear equation systems arise in many areas of science and engineering: e.g. when solving differential equations, in interpolation problems, or in numerical schemes like finite difference.


The package can be installed via pip. On Windows you can install WinPython to get Python and pip running.

pip install pentapy

There are pre-built wheels for Linux, MacOS and Windows for most Python versions (2.7, 3.4-3.7).

If your system is not supported and you want to have the Cython routines of pentapy installed, you have to provide a c-compiler and run:

pip install numpy cython
pip install pentapy

To get the scipy solvers running, you have to install scipy or you can use the following extra argument:

pip install pentapy[all]

Instead of "all" you can also typ "scipy" or "umfpack" to get one of these specific packages.


The solver is based on the algorithms PTRANS-I and PTRANS-II presented by Askar et al. 2015.

Documentation and Examples

You can find the documentation under

Solving a pentadiagonal linear equation system

This is an example of how to solve a LES with a pentadiagonal matrix.

import numpy as np
import pentapy as pp

size = 1000
# create a flattened pentadiagonal matrix
M_flat = (np.random.random((5, size)) - 0.5) * 1e-5
V = np.random.random(size) * 1e5
# solve the LES with M_flat as row-wise flattened matrix
X = pp.solve(M_flat, V, is_flat=True)

# create the corresponding matrix for checking
M = pp.create_full(M_flat, col_wise=False)
# calculate the error
print(np.max(np.abs(, X) - V)))

This should give something like:



In the following a couple of solvers for pentadiagonal systems are compared:


The implementations of pentapy are almost one order of magnitude faster than the scipy algorithms for banded or sparse matrices.

The performance plot was created with perfplot. Have a look at the script: examples/




You can contact us via


MIT © 2019

You can’t perform that action at this time.