skbio.stats.distance.randdm#

skbio.stats.distance.randdm(num_objects, ids=None, constructor=None, random_fn=None)[source]#

Generate a distance matrix populated with random distances.

Using the default random_fn, distances are randomly drawn from a uniform distribution over [0, 1).

Regardless of random_fn, the resulting distance matrix is guaranteed to be symmetric and hollow.

Parameters:
num_objectsint

The number of objects in the resulting distance matrix. For example, if num_objects is 3, a 3x3 distance matrix will be returned.

idssequence of str or None, optional

A sequence of strings to be used as IDs. len(ids) must be equal to num_objects. If not provided, IDs will be monotonically-increasing integers cast as strings (numbering starts at 1). For example, ('1', '2', '3').

constructortype, optional

DissimilarityMatrix or subclass constructor to use when creating the random distance matrix. The returned distance matrix will be of this type. By default, a DistanceMatrix instance will be returned.

random_fnint, np.random.Generator or callable, optional

Functionfor generating random values. It must accept (n_rows, n_columns) and return a 2D array of float-like. Default is the random method of a NumPy random generator. If an integer is provided, a random generator will be constructed using this number as the seed.

Changed in version 0.6.3: Switched to NumPy’s new random generator. Can accept a random seed or random generator instance. The function takes one tuple parameter instead of two separate parameters.

Returns:
DissimilarityMatrix

DissimilarityMatrix (or subclass) instance of random distances. Type depends on constructor.