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
, thenmat
is subsetted along the rows as if we had doneX[indices]
for numpy arrays. Ifaxis=1
, then it is subsetted along the columns as if we had doneX[:, indices]
for numpy arrays.For syntactic sugar, the above numpy syntax works for all naive matrix classes. That is, if
mat
is aMatrixNaiveBaseXX
, thenmat[indices]
andmat[:, indices]
yield the same return values assubset(mat, indices, axis=0, n_threads=n_threads)
andsubset(mat, indices, axis=1, n_threads=n_threads)
, respectively, wheren_threads
is deduced frommat
. 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 alongindices
to0
when supplying the GLM object. For example, suppose the user wishes to runadelie.solver.grpnet()
withmat
andad.glm.gaussian(y)
but subsetting the samples alongindices
. Then, instead of supplyingmat[indices]
andad.glm.gaussian(y[indices])
, we recommend creating a weight vectorw
where it is0
outsideindices
and supplymat
andad.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
isnumpy.ndarray
then the usual numpy subsetted matrix is returned.