Trait ndarray_rand::RandomExt [−][src]
pub trait RandomExt<S, D> where
S: DataOwned,
D: Dimension, { fn random<Sh, IdS>(shape: Sh, distribution: IdS) -> ArrayBase<S, D>
where
IdS: Distribution<S::Elem>,
Sh: ShapeBuilder<Dim = D>; fn random_using<Sh, IdS, R: ?Sized>(
shape: Sh,
distribution: IdS,
rng: &mut R
) -> ArrayBase<S, D>
where
IdS: Distribution<S::Elem>,
R: Rng,
Sh: ShapeBuilder<Dim = D>; }
Constructors for n-dimensional arrays with random elements.
This trait extends ndarray’s ArrayBase
and can not be implemented
for other types.
The default RNG is a fast automatically seeded rng (currently
rand::rngs::SmallRng
seeded from rand::thread_rng
).
Note that SmallRng
is cheap to initialize and fast, but it may generate
low-quality random numbers, and reproducibility is not guaranteed. See its
documentation for information. You can select a different RNG with
.random_using()
.
Required Methods
fn random<Sh, IdS>(shape: Sh, distribution: IdS) -> ArrayBase<S, D> where
IdS: Distribution<S::Elem>,
Sh: ShapeBuilder<Dim = D>,
IdS: Distribution<S::Elem>,
Sh: ShapeBuilder<Dim = D>,
Create an array with shape dim
with elements drawn from
distribution
using the default RNG.
Panics if creation of the RNG fails or if the number of elements overflows usize.
extern crate rand; extern crate ndarray; extern crate ndarray_rand; use rand::distributions::Range; use ndarray::Array; use ndarray_rand::RandomExt; let a = Array::random((2, 5), Range::new(0., 10.)); println!("{:8.4}", a); // Example Output: // [[ 8.6900, 6.9824, 3.8922, 6.5861, 2.4890], // [ 0.0914, 5.5186, 5.8135, 5.2361, 3.1879]]
fn random_using<Sh, IdS, R: ?Sized>(
shape: Sh,
distribution: IdS,
rng: &mut R
) -> ArrayBase<S, D> where
IdS: Distribution<S::Elem>,
R: Rng,
Sh: ShapeBuilder<Dim = D>,
shape: Sh,
distribution: IdS,
rng: &mut R
) -> ArrayBase<S, D> where
IdS: Distribution<S::Elem>,
R: Rng,
Sh: ShapeBuilder<Dim = D>,
Create an array with shape dim
with elements drawn from
distribution
, using a specific Rng rng
.
Panics if the number of elements overflows usize.
Implementations on Foreign Types
impl<S, D> RandomExt<S, D> for ArrayBase<S, D> where
S: DataOwned,
D: Dimension,
[src]
impl<S, D> RandomExt<S, D> for ArrayBase<S, D> where
S: DataOwned,
D: Dimension,
fn random<Sh, IdS>(shape: Sh, dist: IdS) -> ArrayBase<S, D> where
IdS: Distribution<S::Elem>,
Sh: ShapeBuilder<Dim = D>,
[src]
fn random<Sh, IdS>(shape: Sh, dist: IdS) -> ArrayBase<S, D> where
IdS: Distribution<S::Elem>,
Sh: ShapeBuilder<Dim = D>,
fn random_using<Sh, IdS, R: ?Sized>(
shape: Sh,
dist: IdS,
rng: &mut R
) -> ArrayBase<S, D> where
IdS: Distribution<S::Elem>,
R: Rng,
Sh: ShapeBuilder<Dim = D>,
[src]
fn random_using<Sh, IdS, R: ?Sized>(
shape: Sh,
dist: IdS,
rng: &mut R
) -> ArrayBase<S, D> where
IdS: Distribution<S::Elem>,
R: Rng,
Sh: ShapeBuilder<Dim = D>,