Module: algorithms.statistics.utils


nipy.algorithms.statistics.utils.complex(maximal=[(0, 3, 2, 7), (0, 6, 2, 7), (0, 7, 5, 4), (0, 7, 5, 1), (0, 7, 4, 6), (0, 3, 1, 7)])

Faces from simplices

Take a list of maximal simplices (by default a triangulation of a cube into 6 tetrahedra) and computes all faces


maximal : sequence of sequences, optional

Default is triangulation of cube into tetrahedra


faces : dict

nipy.algorithms.statistics.utils.cube_with_strides_center(center=[0, 0, 0], strides=[4, 2, 1])

Cube in an array of voxels with a given center and strides.

This triangulates a cube with vertices [center[i] + 1].

The dimension of the cube is determined by len(center) which should agree with len(center).

The allowable dimensions are [1,2,3].


center : (d,) sequence of int, optional

Default is [0, 0, 0]

strides : (d,) sequence of int, optional

Default is [4, 2, 1]. These are the strides given by np.ones((2,2,2), np.bool).strides


complex : dict

A dictionary with integer keys representing a simplicial complex. The vertices of the simplicial complex are the indices of the corners of the cube in a ‘flattened’ array with specified strides.

nipy.algorithms.statistics.utils.decompose2d(shape, dim=3)

Return all (dim-1)-dimensional simplices in a triangulation of a square of a given shape. The vertices in the triangulation are indices in a ‘flattened’ array of the specified shape.

nipy.algorithms.statistics.utils.decompose3d(shape, dim=4)

Return all (dim-1)-dimensional simplices in a triangulation of a cube of a given shape. The vertices in the triangulation are indices in a ‘flattened’ array of the specified shape.


Join a sequence of simplicial complexes.

Returns the union of all the particular faces.


Compute the inverse of a set of arrays in-place


a: array_like of shape (n_samples, M, M)

Set of square matrices to be inverted. a is changed in place.


a: ndarray shape (n_samples, M, M)

The input array a, overwritten with the inverses of the original 2D arrays in a[0], a[1], .... Thus a[0] replaced with inv(a[0]) etc.


LinAlgError :

If a is singular.

ValueError :

If a is not square, or not 2-dimensional.


This function is copied from scipy.linalg.inv, but with some customizations for speed-up from operating on multiple arrays. It also has some conditionals to work with different scipy versions.

nipy.algorithms.statistics.utils.multiple_mahalanobis(effect, covariance)

Returns the squared Mahalanobis distance for a given set of samples


effect: array of shape (n_features, n_samples),

Each column represents a vector to be evaluated

covariance: array of shape (n_features, n_features, n_samples),

Corresponding covariance models stacked along the last axis


sqd: array of shape (n_samples,)

the squared distances (one per sample)


Return the z-score corresponding to a given p-value.