Skip to content

Commit 20c1ff5

Browse files
committed
Document with how to control the return type
1 parent 07bedad commit 20c1ff5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/impl_constructors.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ where
337337

338338
/// Create an array with zeros, shape `shape`.
339339
///
340+
/// The element type is inferred; to control it, you can either specify
341+
/// type of the returned array or use turbofish syntax in the function call:
342+
/// ```
343+
/// use ndarray::{Array1, Array2};
344+
///
345+
/// // Specify f32
346+
/// let arr_f32: Array1<f32> = Array1::zeros(3);
347+
/// assert_eq!(arr_f32, [0_f32, 0, 0]);
348+
///
349+
/// // Specify i64
350+
/// let arr_i64 = Array2::<i64>::zeros((2, 2));
351+
/// assert_eq!(arr_i64, [[0_i64, 0], [0, 0]]);
352+
/// ```
353+
///
340354
/// **Panics** if the product of non-zero axis lengths overflows `isize`.
341355
pub fn zeros<Sh>(shape: Sh) -> Self
342356
where

0 commit comments

Comments
 (0)