Skip to content

Commit

Permalink
DOC: Add example to from_shape_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Sep 28, 2019
1 parent 1181615 commit d8d76fa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/impl_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,20 @@ where
/// visited in arbitrary order.
///
/// **Panics** if the product of non-zero axis lengths overflows `isize`.
///
/// ```
/// use ndarray::{Array, arr2};
///
/// // Create a table of i × j (with i and j from 1 to 3)
/// let ij_table = Array::from_shape_fn((3, 3), |(i, j)| (1 + i) * (1 + j));
///
/// assert_eq!(
/// ij_table,
/// arr2(&[[1, 2, 3],
/// [2, 4, 6],
/// [3, 6, 9]])
/// );
/// ```
pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
where
Sh: ShapeBuilder<Dim = D>,
Expand Down

0 comments on commit d8d76fa

Please sign in to comment.