Skip to content

Commit e9ef450

Browse files
authored
Merge pull request #704 from LukeMathWalker/docs
Docs polishing
2 parents 01f7505 + 2f511bb commit e9ef450

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/doc/ndarray_for_numpy_users/mod.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//!
1010
//! * [Similarities](#similarities)
1111
//! * [Some key differences](#some-key-differences)
12+
//! * [The ndarray ecosystem](#the-ndarray-ecosystem)
1213
//! * [Other Rust array/matrix crates](#other-rust-arraymatrix-crates)
1314
//! * [Rough `ndarray`–NumPy equivalents](#rough-ndarraynumpy-equivalents)
1415
//!
@@ -116,6 +117,20 @@
116117
//! </tr>
117118
//! </table>
118119
//!
120+
//! # The ndarray ecosystem
121+
//!
122+
//! `ndarray` does not provide advanced linear algebra routines out of the box (e.g. SVD decomposition).
123+
//! Most of the routines that you can find in `scipy.linalg`/`numpy.linalg` are provided by another crate,
124+
//! [`ndarray-linalg`](https://crates.io/crates/ndarray-linalg).
125+
//!
126+
//! The same holds for statistics: `ndarray` provides some basic functionalities (e.g. `mean`)
127+
//! but more advanced routines can be found in [`ndarray-stats`](https://crates.io/crates/ndarray-stats).
128+
//!
129+
//! If you are looking to generate random arrays instead, check out [`ndarray-rand`](https://crates.io/crates/ndarray-rand).
130+
//!
131+
//! It is also possible to serialize `NumPy` arrays in `.npy`/`.npz` format and deserialize them as `ndarray` arrays (and vice versa)
132+
//! using [`ndarray-npy`](https://crates.io/crates/ndarray-npy).
133+
//!
119134
//! # Other Rust array/matrix crates
120135
//!
121136
//! Of the array/matrix types in Rust crates, the `ndarray` array type is probably
@@ -145,10 +160,7 @@
145160
//! so it's not restricted to 1-D and 2-D vectors and matrices. Also, operators
146161
//! operate elementwise by default, so the multiplication operator `*` performs
147162
//! elementwise multiplication instead of matrix multiplication. (You have to
148-
//! specifically call `.dot()` if you want matrix multiplication.) Linear algebra
149-
//! with `ndarray` is provided by other crates, e.g.
150-
//! [`ndarray-linalg`](https://crates.io/crates/ndarray-linalg) and
151-
//! [`linxal`](https://crates.io/crates/linxal).
163+
//! specifically call `.dot()` if you want matrix multiplication.)
152164
//!
153165
//! # Rough `ndarray`–NumPy equivalents
154166
//!
@@ -185,12 +197,15 @@
185197
//! `np.array([[1.,2.,3.], [4.,5.,6.]])` | [`array![[1.,2.,3.], [4.,5.,6.]]`][array!] or [`arr2(&[[1.,2.,3.], [4.,5.,6.]])`][arr2()] | 2×3 floating-point array literal
186198
//! `np.arange(0., 10., 0.5)` or `np.r_[:10.:0.5]` | [`Array::range(0., 10., 0.5)`][::range()] | create a 1-D array with values `0.`, `0.5`, …, `9.5`
187199
//! `np.linspace(0., 10., 11)` or `np.r_[:10.:11j]` | [`Array::linspace(0., 10., 11)`][::linspace()] | create a 1-D array with 11 elements with values `0.`, …, `10.`
200+
//! `np.logspace(2.0, 3.0, num=4, base=10.0)` | [`Array::logspace(10.0, 2.0, 3.0, 4)`][::logspace()] | create a 1-D array with 4 elements with values `100.`, `215.4`, `464.1`, `1000.`
201+
//! `np.geomspace(1., 1000., num=4)` | [`Array::geomspace(1e0, 1e3, 4)`][::geomspace()] | create a 1-D array with 4 elements with values `1.`, `10.`, `100.`, `1000.`
188202
//! `np.ones((3, 4, 5))` | [`Array::ones((3, 4, 5))`][::ones()] | create a 3×4×5 array filled with ones (inferring the element type)
189203
//! `np.zeros((3, 4, 5))` | [`Array::zeros((3, 4, 5))`][::zeros()] | create a 3×4×5 array filled with zeros (inferring the element type)
190204
//! `np.zeros((3, 4, 5), order='F')` | [`Array::zeros((3, 4, 5).f())`][::zeros()] | create a 3×4×5 array with Fortran (column-major) memory layout filled with zeros (inferring the element type)
191205
//! `np.zeros_like(a, order='C')` | [`Array::zeros(a.raw_dim())`][::zeros()] | create an array of zeros of the shape shape as `a`, with row-major memory layout (unlike NumPy, this infers the element type from context instead of duplicating `a`'s element type)
192206
//! `np.full((3, 4), 7.)` | [`Array::from_elem((3, 4), 7.)`][::from_elem()] | create a 3×4 array filled with the value `7.`
193207
//! `np.eye(3)` | [`Array::eye(3)`][::eye()] | create a 3×3 identity matrix (inferring the element type)
208+
//! `np.diag(np.array([1, 2, 3]))` | [`Array2::from_diag(&arr1(&[1, 2, 3]))`][::from_diag()] | create a 3×3 matrix with `[1, 2, 3]` as diagonal and zeros elsewhere (inferring the element type)
194209
//! `np.array([1, 2, 3, 4]).reshape((2, 2))` | [`Array::from_shape_vec((2, 2), vec![1, 2, 3, 4])?`][::from_shape_vec()] | create a 2×2 array from the elements in the list/`Vec`
195210
//! `np.array([1, 2, 3, 4]).reshape((2, 2), order='F')` | [`Array::from_shape_vec((2, 2).f(), vec![1, 2, 3, 4])?`][::from_shape_vec()] | create a 2×2 array from the elements in the list/`Vec` using Fortran (column-major) order
196211
//! `np.random` | See the [`ndarray-rand`](https://crates.io/crates/ndarray-rand) crate. | create arrays of random numbers
@@ -447,8 +462,7 @@
447462
//!
448463
//! </td><td>
449464
//!
450-
//! `a.sum() / a.len() as f64`
451-
//!
465+
//! [`a.mean().unwrap()`][.mean()]
452466
//! </td><td>
453467
//!
454468
//! calculate the mean of the elements in `f64` array `a`
@@ -479,7 +493,7 @@
479493
//!
480494
//! </td><td>
481495
//!
482-
//! check if the arrays' elementwise differences are within an absolute tolerance
496+
//! check if the arrays' elementwise differences are within an absolute tolerance (it requires the `approx` feature-flag)
483497
//!
484498
//! </td></tr>
485499
//!
@@ -503,9 +517,7 @@
503517
//!
504518
//! </td><td>
505519
//!
506-
//! See other crates, e.g.
507-
//! [`ndarray-linalg`](https://crates.io/crates/ndarray-linalg) and
508-
//! [`linxal`](https://crates.io/crates/linxal).
520+
//! See [`ndarray-linalg`](https://crates.io/crates/ndarray-linalg)
509521
//!
510522
//! </td><td>
511523
//!
@@ -584,6 +596,7 @@
584596
//! [.fold_axis()]: ../../struct.ArrayBase.html#method.fold_axis
585597
//! [::from_elem()]: ../../struct.ArrayBase.html#method.from_elem
586598
//! [::from_iter()]: ../../struct.ArrayBase.html#method.from_iter
599+
//! [::from_diag()]: ../../struct.ArrayBase.html#method.from_diag
587600
//! [::from_shape_fn()]: ../../struct.ArrayBase.html#method.from_shape_fn
588601
//! [::from_shape_vec()]: ../../struct.ArrayBase.html#method.from_shape_vec
589602
//! [::from_shape_vec_unchecked()]: ../../struct.ArrayBase.html#method.from_shape_vec_unchecked
@@ -598,13 +611,16 @@
598611
//! [.len()]: ../../struct.ArrayBase.html#method.len
599612
//! [.len_of()]: ../../struct.ArrayBase.html#method.len_of
600613
//! [::linspace()]: ../../struct.ArrayBase.html#method.linspace
614+
//! [::logspace()]: ../../struct.ArrayBase.html#method.logspace
615+
//! [::geomspace()]: ../../struct.ArrayBase.html#method.geomspace
601616
//! [.map()]: ../../struct.ArrayBase.html#method.map
602617
//! [.map_axis()]: ../../struct.ArrayBase.html#method.map_axis
603618
//! [.map_inplace()]: ../../struct.ArrayBase.html#method.map_inplace
604619
//! [.mapv()]: ../../struct.ArrayBase.html#method.mapv
605620
//! [.mapv_inplace()]: ../../struct.ArrayBase.html#method.mapv_inplace
606621
//! [.mapv_into()]: ../../struct.ArrayBase.html#method.mapv_into
607622
//! [matrix-* dot]: ../../struct.ArrayBase.html#method.dot-1
623+
//! [.mean()]: ../../struct.ArrayBase.html#method.mean
608624
//! [.mean_axis()]: ../../struct.ArrayBase.html#method.mean_axis
609625
//! [.ndim()]: ../../struct.ArrayBase.html#method.ndim
610626
//! [NdProducer]: ../../trait.NdProducer.html

src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@
9292
//!
9393
//! * If you have experience with NumPy, you may also be interested in
9494
//! [`ndarray_for_numpy_users`](doc/ndarray_for_numpy_users/index.html).
95+
//!
96+
//! ## The ndarray ecosystem
97+
//!
98+
//! `ndarray` provides a lot of functionality, but it's not a one-stop solution.
99+
//!
100+
//! `ndarray` includes matrix multiplication and other binary/unary operations out of the box.
101+
//! More advanced linear algebra routines (e.g. SVD decomposition or eigenvalue computation)
102+
//! can be found in [`ndarray-linalg`](https://crates.io/crates/ndarray-linalg).
103+
//!
104+
//! The same holds for statistics: `ndarray` provides some basic functionalities (e.g. `mean`)
105+
//! but more advanced routines can be found in [`ndarray-stats`](https://crates.io/crates/ndarray-stats).
106+
//!
107+
//! If you are looking to generate random arrays instead, check out [`ndarray-rand`](https://crates.io/crates/ndarray-rand).
95108
96109
#[cfg(feature = "blas")]
97110
extern crate blas_src;

0 commit comments

Comments
 (0)