|
194 | 194 | //! `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
|
195 | 195 | //! `np.random` | See the [`ndarray-rand`](https://crates.io/crates/ndarray-rand) crate. | create arrays of random numbers
|
196 | 196 | //!
|
| 197 | +//! Note that the examples in the table rely on the compiler inferring the |
| 198 | +//! element type and dimensionality from context, which is usually sufficient. |
| 199 | +//! However, if the compiler cannot infer the types, you can specify them |
| 200 | +//! manually. These are examples of creating a 3-D Fortran-layout array of |
| 201 | +//! `f64`s: |
| 202 | +//! |
| 203 | +//! ``` |
| 204 | +//! # use ndarray::prelude::*; |
| 205 | +//! # |
| 206 | +//! // This is an example where the compiler can infer the element type |
| 207 | +//! // because `f64::sin` can only be called on `f64` elements: |
| 208 | +//! let arr1 = Array::zeros((3, 2, 4).f()); |
| 209 | +//! arr1.mapv(f64::sin); |
| 210 | +//! |
| 211 | +//! // Specify just the element type and infer the dimensionality: |
| 212 | +//! let arr2 = Array::<f64, _>::zeros((3, 2, 4).f()); |
| 213 | +//! let arr3: Array<f64, _> = Array::zeros((3, 2, 4).f()); |
| 214 | +//! |
| 215 | +//! // Specify both the element type and dimensionality: |
| 216 | +//! let arr4 = Array3::<f64>::zeros((3, 2, 4).f()); |
| 217 | +//! let arr5: Array3<f64> = Array::zeros((3, 2, 4).f()); |
| 218 | +//! let arr6 = Array::<f64, Ix3>::zeros((3, 2, 4).f()); |
| 219 | +//! let arr7: Array<f64, Ix3> = Array::zeros((3, 2, 4).f()); |
| 220 | +//! ``` |
| 221 | +//! |
197 | 222 | //! ## Indexing and slicing
|
198 | 223 | //!
|
199 | 224 | //! A few notes:
|
|
0 commit comments