Generate independent Bernoulli random variables above the diagonal and set everything else to zero. Taking the strict upper triangle of a random square array gives each allowed entry probability of being one:
import numpy as np
rng = np.random.default_rng(2024)
def rand_triu(n):
return np.triu(rng.integers(0, 2, size=(n, n)), k=1)
example = rand_triu(10)
print(example)One reproducible strictly upper triangular matrix is:
0 1 0 0 0 0 1 1 1 1
0 0 1 0 0 0 1 0 0 0
0 0 0 1 1 0 0 1 1 0
0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0Every matrix returned in this way is a nilpotent matrix; randomness affects its nilpotency index, not the fact of the nilpotent property.
Articles by others on the same topic
There are currently no matching articles.