2

In NumPy, I can use random package to create a 2D array, but cannot make sure it has full rank or a particular rank. How to got it? In the case of full rank, I can use linalg.matrix_rank to check, but I want to make sure this in more simple way. A solution for the case of square matrix is welcome.

Edit: When I ask this question, I think to builtin solution in Numpy. But if there's not that kind of solution in Numpy, Scipy (or other Python modules), the situation here may as in @hpaulj's comment "But at some level this sounds more like a theoretical math topic than a Numpy programming one." And as the math topic, the question should be: find algorithm to generate a random matrix (random in uniform distribution) that has a particular rank? So, closing this question or keeping it to wait nice algorithms in Python is the admin's choice.

ydhhat
  • 381
  • 2
  • 15
  • 1
    Depending on the final goal, you can start by doing an SVD of a starting matrix M=U*Sigma*Vt and then only randomize the eigenvalues on Sigma. The new matrix will then be given by M'=USigma_newVt with the rank given by the number of non-zero entries in Sigma'. This can only be a solution depending on the desired level of randomness. Please someone correct me if I'm wrong. – Vasco Ludovico Oct 01 '21 at 17:27
  • random with floats, such as `np.random.rand(20,20)` is almost guaranteed to be full rank. There are so many different possible float values, repeats are unlikely, much less repeated patterns that could reduce the rank. With random ints in a small range the probably of reduced rank is a bit higher. But at some level this sounds more like a theoretical math topic than a `numpy` programming one. – hpaulj Oct 01 '21 at 19:11

0 Answers0