From 0a628430590450828aeb3669f58631f62bf22691 Mon Sep 17 00:00:00 2001 From: bluss Date: Sat, 28 Sep 2019 18:31:23 +0200 Subject: [PATCH] DOC: Add example to from_shape_fn --- src/impl_constructors.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index f0d0e8d58..4287d2bb7 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -333,6 +333,20 @@ where /// visited in arbitrary order. /// /// **Panics** if the product of non-zero axis lengths overflows `isize`. + /// + /// ``` + /// use ndarray::{Array2, arr2}; + /// + /// // Create a table of i × j (with i and j from 1 to 3) + /// let ij_table = Array2::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(shape: Sh, f: F) -> Self where Sh: ShapeBuilder,