Skip to content

Commit aa135d4

Browse files
authored
Document Array::zeros with how to control the return type (#1524)
1 parent a141f37 commit aa135d4

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, arr1};
344+
///
345+
/// // Specify f32
346+
/// let arr_f32: Array1<f32> = Array1::zeros(3);
347+
/// assert_eq!(arr_f32, arr1(&[0_f32, 0.0, 0.0]));
348+
///
349+
/// // Specify i64
350+
/// let arr_i64 = Array1::<i64>::zeros(3);
351+
/// assert_eq!(arr_i64, arr1(&[0_i64, 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)