adelie.matrix.subset#

adelie.matrix.subset(mat: ndarray | MatrixNaiveBase32 | MatrixNaiveBase64, indices: ndarray, *, axis: int = 0, n_threads: int = 1)[source]#

Creates a subset of the matrix along an axis.

If axis=0, then mat is subsetted along the rows as if we had done X[indices] for numpy arrays. If axis=1, then it is subsetted along the columns as if we had done X[:, indices] for numpy arrays.

For syntactic sugar, the above numpy syntax works for all naive matrix classes. That is, if mat is a MatrixNaiveBaseXX, then mat[indices] and mat[:, indices] yield the same return values as subset(mat, indices, axis=0, n_threads=n_threads) and subset(mat, indices, axis=1, n_threads=n_threads), respectively, where n_threads is deduced from mat. This function allows the user to further specify the number of threads.

Note

This matrix only works for naive method!

Warning

For users intending to subset rows of mat and pass the subsetted matrix to our group elastic net solver, it is much more efficient to rather set observation weights along indices to 0 when supplying the GLM object. For example, suppose the user wishes to run adelie.solver.grpnet() with mat and ad.glm.gaussian(y) but subsetting the samples along indices. Then, instead of supplying mat[indices] and ad.glm.gaussian(y[indices]), we recommend creating a weight vector w where it is 0 outside indices and supply mat and ad.glm.gaussian(y, weights=w).

Parameters:
matUnion[ndarray, MatrixNaiveBase32, MatrixNaiveBase64]

The matrix to subset.

indicesndarray

Array of indices to subset the matrix.

axisint, optional

The axis along which to subset. Default is 0.

n_threadsint, optional

Number of threads. Default is 1.

Returns:
wrap

Wrapper matrix object. If mat is numpy.ndarray then the usual numpy subsetted matrix is returned.