vendredi 26 mai 2023

Generate initial segments of random n-dimensional infinite array in numpy

Consider the following function:

def random_matrix(rows, cols):
    rng = np.random.default_rng(0)
    return rng.random((rows, cols))

How can I make a function f that makes random matrices like random_matrix but has the property that, for all r1, r2, c1, c2, f(r1, c1)[:min(r1, r2), :min(c1, c2)] is equal to f(r2, c2)[:min(r1, r2), :min(c1, c2)]? (This is the two-dimensional case of the slightly more general question in the title. The 1-dimensional case is trivial since it is numpy's normal behavior.)




Aucun commentaire:

Enregistrer un commentaire