{ } Raw JSON

bundles / scipy latest / scipy / stats / _multivariate / uniform_direction_gen

class

scipy.stats._multivariate:uniform_direction_gen

source: /scipy/stats/_multivariate.py :6537

Signature

class   uniform_direction_gen ( seed = None )

Members

Summary

A vector-valued uniform direction.

Extended Summary

Return a random direction (unit vector). The dim keyword specifies the dimensionality of the space.

Parameters

dim : scalar

Dimension of directions.

seed : {None, int, `numpy.random.Generator`,

numpy.random.RandomState}, optional

Used for drawing random variates. If seed is None, the ~np.random.RandomState singleton is used. If seed is an int, a new RandomState instance is used, seeded with seed. If seed is already a RandomState or Generator instance, then that object is used. Default is None.

Methods

rvs(dim=None, size=1, random_state=None)

Draw random directions.

Notes

This distribution generates unit vectors uniformly distributed on the surface of a hypersphere. These can be interpreted as random directions. For example, if dim is 3, 3D vectors from the surface of will be sampled.

Examples

import numpy as np
from scipy.stats import uniform_direction
x = uniform_direction.rvs(3)
np.linalg.norm(x)
This generates one random direction, a vector on the surface of :math:`S^2`. Alternatively, the object may be called (as a function) to return a frozen distribution with fixed `dim` parameter. Here, we create a `uniform_direction` with ``dim=3`` and draw 5 observations. The samples are then arranged in an array of shape 5x3.
rng = np.random.default_rng()
uniform_sphere_dist = uniform_direction(3)
unit_vectors = uniform_sphere_dist.rvs(5, random_state=rng)
unit_vectors

Aliases

  • scipy.stats._multivariate.uniform_direction_gen