|
9 | 9 | //!
|
10 | 10 | //! * [Similarities](#similarities)
|
11 | 11 | //! * [Some key differences](#some-key-differences)
|
| 12 | +//! * [The ndarray ecosystem](#the-ndarray-ecosystem) |
12 | 13 | //! * [Other Rust array/matrix crates](#other-rust-arraymatrix-crates)
|
13 | 14 | //! * [Rough `ndarray`–NumPy equivalents](#rough-ndarraynumpy-equivalents)
|
14 | 15 | //!
|
|
116 | 117 | //! </tr>
|
117 | 118 | //! </table>
|
118 | 119 | //!
|
| 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 | +//! |
119 | 134 | //! # Other Rust array/matrix crates
|
120 | 135 | //!
|
121 | 136 | //! Of the array/matrix types in Rust crates, the `ndarray` array type is probably
|
|
145 | 160 | //! so it's not restricted to 1-D and 2-D vectors and matrices. Also, operators
|
146 | 161 | //! operate elementwise by default, so the multiplication operator `*` performs
|
147 | 162 | //! 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.) |
152 | 164 | //!
|
153 | 165 | //! # Rough `ndarray`–NumPy equivalents
|
154 | 166 | //!
|
|
185 | 197 | //! `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
|
186 | 198 | //! `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`
|
187 | 199 | //! `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.` |
188 | 202 | //! `np.ones((3, 4, 5))` | [`Array::ones((3, 4, 5))`][::ones()] | create a 3×4×5 array filled with ones (inferring the element type)
|
189 | 203 | //! `np.zeros((3, 4, 5))` | [`Array::zeros((3, 4, 5))`][::zeros()] | create a 3×4×5 array filled with zeros (inferring the element type)
|
190 | 204 | //! `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)
|
191 | 205 | //! `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)
|
192 | 206 | //! `np.full((3, 4), 7.)` | [`Array::from_elem((3, 4), 7.)`][::from_elem()] | create a 3×4 array filled with the value `7.`
|
193 | 207 | //! `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) |
194 | 209 | //! `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`
|
195 | 210 | //! `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
|
196 | 211 | //! `np.random` | See the [`ndarray-rand`](https://crates.io/crates/ndarray-rand) crate. | create arrays of random numbers
|
|
447 | 462 | //!
|
448 | 463 | //! </td><td>
|
449 | 464 | //!
|
450 |
| -//! `a.sum() / a.len() as f64` |
451 |
| -//! |
| 465 | +//! [`a.mean().unwrap()`][.mean()] |
452 | 466 | //! </td><td>
|
453 | 467 | //!
|
454 | 468 | //! calculate the mean of the elements in `f64` array `a`
|
|
479 | 493 | //!
|
480 | 494 | //! </td><td>
|
481 | 495 | //!
|
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) |
483 | 497 | //!
|
484 | 498 | //! </td></tr>
|
485 | 499 | //!
|
|
503 | 517 | //!
|
504 | 518 | //! </td><td>
|
505 | 519 | //!
|
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) |
509 | 521 | //!
|
510 | 522 | //! </td><td>
|
511 | 523 | //!
|
|
584 | 596 | //! [.fold_axis()]: ../../struct.ArrayBase.html#method.fold_axis
|
585 | 597 | //! [::from_elem()]: ../../struct.ArrayBase.html#method.from_elem
|
586 | 598 | //! [::from_iter()]: ../../struct.ArrayBase.html#method.from_iter
|
| 599 | +//! [::from_diag()]: ../../struct.ArrayBase.html#method.from_diag |
587 | 600 | //! [::from_shape_fn()]: ../../struct.ArrayBase.html#method.from_shape_fn
|
588 | 601 | //! [::from_shape_vec()]: ../../struct.ArrayBase.html#method.from_shape_vec
|
589 | 602 | //! [::from_shape_vec_unchecked()]: ../../struct.ArrayBase.html#method.from_shape_vec_unchecked
|
|
598 | 611 | //! [.len()]: ../../struct.ArrayBase.html#method.len
|
599 | 612 | //! [.len_of()]: ../../struct.ArrayBase.html#method.len_of
|
600 | 613 | //! [::linspace()]: ../../struct.ArrayBase.html#method.linspace
|
| 614 | +//! [::logspace()]: ../../struct.ArrayBase.html#method.logspace |
| 615 | +//! [::geomspace()]: ../../struct.ArrayBase.html#method.geomspace |
601 | 616 | //! [.map()]: ../../struct.ArrayBase.html#method.map
|
602 | 617 | //! [.map_axis()]: ../../struct.ArrayBase.html#method.map_axis
|
603 | 618 | //! [.map_inplace()]: ../../struct.ArrayBase.html#method.map_inplace
|
604 | 619 | //! [.mapv()]: ../../struct.ArrayBase.html#method.mapv
|
605 | 620 | //! [.mapv_inplace()]: ../../struct.ArrayBase.html#method.mapv_inplace
|
606 | 621 | //! [.mapv_into()]: ../../struct.ArrayBase.html#method.mapv_into
|
607 | 622 | //! [matrix-* dot]: ../../struct.ArrayBase.html#method.dot-1
|
| 623 | +//! [.mean()]: ../../struct.ArrayBase.html#method.mean |
608 | 624 | //! [.mean_axis()]: ../../struct.ArrayBase.html#method.mean_axis
|
609 | 625 | //! [.ndim()]: ../../struct.ArrayBase.html#method.ndim
|
610 | 626 | //! [NdProducer]: ../../trait.NdProducer.html
|
|
0 commit comments