# 15.1.1.7.1.1. cobra.util.array¶

## 15.1.1.7.1.1.1. Module Contents¶

cobra.util.array.create_stoichiometric_matrix(model, array_type="dense", dtype=None)[source]

Return a stoichiometric array representation of the given model.

The the columns represent the reactions and rows represent metabolites. S[i,j] therefore contains the quantity of metabolite i produced (negative for consumed) by reaction j.

Parameters: model (cobra.Model) – The cobra model to construct the matrix for. array_type (string) – The type of array to construct. if ‘dense’, return a standard numpy.array, ‘dok’, or ‘lil’ will construct a sparse array using scipy of the corresponding type and ‘DataFrame’ will give a pandas DataFrame with metabolite indices and reaction columns dtype (data-type) – The desired data-type for the array. If not given, defaults to float. The stoichiometric matrix for the given model. matrix of class dtype
cobra.util.array.nullspace(A, atol=1e-13, rtol=0)[source]

Compute an approximate basis for the nullspace of A. The algorithm used by this function is based on the singular value decomposition of A.

Parameters: A (numpy.ndarray) – A should be at most 2-D. A 1-D array with length k will be treated as a 2-D with shape (1, k) atol (float) – The absolute tolerance for a zero singular value. Singular values smaller than atol are considered to be zero. rtol (float) – The relative tolerance. Singular values less than rtol*smax are considered to be zero, where smax is the largest singular value. both atol and rtol are positive, the combined tolerance is the (If) –

:param maximum of the two; that is::: :param tol = max(atol, rtol * smax): :param Singular values smaller than tol are considered to be zero.:

Returns: If A is an array with shape (m, k), then ns will be an array with shape (k, n), where n is the estimated dimension of the nullspace of A. The columns of ns are a basis for the nullspace; each element in numpy.dot(A, ns) will be approximately zero. numpy.ndarray

Notes

Taken from the numpy cookbook.

cobra.util.array.constraint_matrices(model, array_type="dense", include_vars=False, zero_tol=1e-06)[source]

Create a matrix representation of the problem.

This is used for alternative solution approaches that do not use optlang. The function will construct the equality matrix, inequality matrix and bounds for the complete problem.

Notes

To accomodate non-zero equalities the problem will add the variable “const_one” which is a variable that equals one.

Parameters: model (cobra.Model) – The model from which to obtain the LP problem. array_type (string) – The type of array to construct. if ‘dense’, return a standard numpy.array, ‘dok’, or ‘lil’ will construct a sparse array using scipy of the corresponding type and ‘DataFrame’ will give a pandas DataFrame with metabolite indices and reaction columns. zero_tol (float) – The zero tolerance used to judge whether two bounds are the same. A named tuple consisting of 6 matrices and 2 vectors: - “equalities” is a matrix S such that S*vars = b. It includes a row for each constraint and one column for each variable. ”b” the right side of the equality equation such that S*vars = b. ”inequalities” is a matrix M such that lb <= M*vars <= ub. It contains a row for each inequality and as many columns as variables. ”bounds” is a compound matrix [lb ub] containing the lower and upper bounds for the inequality constraints in M. ”variable_fixed” is a boolean vector indicating whether the variable at that index is fixed (lower bound == upper_bound) and is thus bounded by an equality constraint. ”variable_bounds” is a compound matrix [lb ub] containing the lower and upper bounds for all variables. collections.namedtuple