mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
22 lines
629 B
Python
22 lines
629 B
Python
|
import numpy as np
|
||
|
|
||
|
|
||
|
def hypercube_points(
|
||
|
num_points: int, hypercube_size: float, num_dimensions: int
|
||
|
) -> np.ndarray:
|
||
|
"""
|
||
|
Generates random points uniformly distributed within an n-dimensional hypercube.
|
||
|
|
||
|
Args:
|
||
|
num_points: Number of points to generate.
|
||
|
hypercube_size: Size of the hypercube.
|
||
|
num_dimensions: Number of dimensions of the hypercube.
|
||
|
|
||
|
Returns:
|
||
|
An array of shape (num_points, num_dimensions)
|
||
|
with generated points.
|
||
|
"""
|
||
|
rng = np.random.default_rng()
|
||
|
shape = (num_points, num_dimensions)
|
||
|
return hypercube_size * rng.random(shape)
|