#ndarray #multi-dimensional #rand #random #matrix #uniform-distribution

ndarray-rand

Constructors for randomized arrays. rand integration for ndarray.

18 releases (breaking)

0.15.0 Aug 3, 2024
0.14.0 Mar 27, 2021
0.13.0 Dec 21, 2020
0.12.0 Nov 29, 2020
0.1.0 Mar 29, 2016

#77 in Algorithms

Download history 17780/week @ 2024-07-17 14617/week @ 2024-07-24 19957/week @ 2024-07-31 20195/week @ 2024-08-07 22733/week @ 2024-08-14 20408/week @ 2024-08-21 17588/week @ 2024-08-28 19599/week @ 2024-09-04 21439/week @ 2024-09-11 18704/week @ 2024-09-18 20661/week @ 2024-09-25 22002/week @ 2024-10-02 20770/week @ 2024-10-09 19992/week @ 2024-10-16 22887/week @ 2024-10-23 17568/week @ 2024-10-30

85,248 downloads per month
Used in 172 crates (139 directly)

MIT/Apache

1MB
17K SLoC

ndarray-rand

Constructors for randomized arrays: rand's integration with ndarray.

Example

Generate a 2-dimensional array with shape (2,5) and elements drawn from a uniform distribution over the (0., 10.) interval:

use ndarray::Array;
use ndarray_rand::RandomExt;
use ndarray_rand::rand_distr::Uniform;

fn main() {
    let a = Array::random((2, 5), Uniform::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]]
}

Dependencies

ndarray-rand depends on rand.

rand and rand-distr are re-exported as sub-modules, ndarray_rand::rand and ndarray_rand::rand_distr respectively. Please rely on these submodules for guaranteed version compatibility.

If you want to use a random number generator or distribution from another crate with ndarray-rand, you need to make sure that the other crate also depends on the same version of rand. Otherwise, the compiler may return errors saying that the items are not compatible (e.g. that a type doesn't implement a necessary trait).

Recent changes

Check RELEASES.md to see the changes introduced in previous releases.

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

Dependencies

~1.3–1.8MB
~33K SLoC