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 ofrandom_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 tonum_objects
. If not provided, IDs will be monotonically-increasing integers cast as strings (numbering starts at 1). For example,('1', '2', '3')
.- constructortype, optional
PairwiseMatrix
or its subclass to use when creating the random distance matrix. The returned matrix will be of this type. By default, aDistanceMatrix
instance will be returned.- random_fnint, np.random.Generator or callable, optional
Function for 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:
- PairwiseMatrix
PairwiseMatrix
(or subclass) instance of random distances. Type depends onconstructor
.
See also