SkillAgentSearch skills...

Pyttb

Python Tensor Toolbox

Install / Use

/learn @sandialabs/Pyttb
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Copyright 2025 National Technology & Engineering Solutions of Sandia,
LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the
U.S. Government retains certain rights in this software.

Regression tests Coverage Status pypi package image Ruff Code style: black

pyttb: Python Tensor Toolbox

Welcome to pyttb, a refactor of the Tensor Toolbox for MATLAB in Python.

This package contains data classes and methods for manipulating dense, sparse, and structured tensors, along with algorithms for computing low-rank tensor decompositions:

Quick Start

Installation

python3 -m pip install pyttb

Example

>>> import pyttb as ttb
>>> X = ttb.tenrand((2,2,2))
>>> type(X)
<class 'pyttb.tensor.tensor'>
>>> M = ttb.cp_als(X, rank=1)
CP_ALS:
 Iter 0: f = 7.367245e-01 f-delta = 7.4e-01
 Iter 1: f = 7.503069e-01 f-delta = 1.4e-02
 Iter 2: f = 7.508240e-01 f-delta = 5.2e-04
 Iter 3: f = 7.508253e-01 f-delta = 1.3e-06
 Final f = 7.508253e-01

Memory layout

For historical reasons we use Fortran memory layouts, where numpy by default uses C. This is relevant for indexing. In the future we hope to extend support for both.

>>> import numpy as np
>>> c_order = np.arange(8).reshape((2,2,2))
>>> f_order = np.arange(8).reshape((2,2,2), order="F")
>>> print(c_order[0,1,1])
3
>>> print(f_order[0,1,1])
6
<!-- markdown-link-check-disable -->

Getting Help

<!-- markdown-link-check-enable -->

Contributing

Citing pyttb in your work

If you use pyttb in your work, please cite it using the citation info here.

Related Skills

View on GitHub
GitHub Stars49
CategoryData
Updated14d ago
Forks17

Languages

Python

Security Score

80/100

Audited on Mar 17, 2026

No findings