freealg.submatrix#
- freealg.submatrix(matrix, size, block_size=None, paired=True, haar=False, seed=None)#
Randomly sample a submatrix from a larger matrix.
- Parameters:
- matrixnumpy.ndarray
A 2D square array
- sizeint
Number of rows and columns of the output submatrix.
- block_sizeint, default=None
If given, sampling is performed at the block level where contiguous blocks of size
block_sizeare selected and preserved. The outputsizeshould be an integer multiple ofblock_size.- pairedbool, default=True
If True, the rows and columns are sampled with the same random indices. If False, separate random indices are used for selecting rows and columns.
- haarbool, default=False
If True, apply a random orthogonal conjugation to the input matrix before sampling, using a Haar-distributed orthogonal matrix. Note that this can significantly increase the runtime for large matrices.
- seedint, default=None
Seed for random number generation. If None, results will not be reproducible.
- Returns:
- subnumpy.ndarray
A 2D array with the number of rows/columns specified by
size.
See also
Examples
>>> import numpy >>> from freealg import submatrix >>> A = numpy.random.randn(1000, 1000) >>> B = submatrix(A, size=500, paired=True, seed=0)