Skip to content

Commit c516803

Browse files
committed
DOC: Add example to from_shape_fn
1 parent 0e4729d commit c516803

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/impl_constructors.rs

+14
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,20 @@ where
336336
/// visited in arbitrary order.
337337
///
338338
/// **Panics** if the product of non-zero axis lengths overflows `isize`.
339+
///
340+
/// ```
341+
/// use ndarray::{Array, arr2};
342+
///
343+
/// // Create a table of i × j (with i and j from 1 to 3)
344+
/// let ij_table = Array::from_shape_fn((3, 3), |(i, j)| (1 + i) * (1 + j));
345+
///
346+
/// assert_eq!(
347+
/// ij_table,
348+
/// arr2(&[[1, 2, 3],
349+
/// [2, 4, 6],
350+
/// [3, 6, 9]])
351+
/// );
352+
/// ```
339353
pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
340354
where
341355
Sh: ShapeBuilder<Dim = D>,

0 commit comments

Comments
 (0)