|
50 | 50 | /// Return the number of rows (length of `Axis(0)`) in the two-dimensional array.
|
51 | 51 | ///
|
52 | 52 | /// ```
|
53 |
| - /// use ndarray::array; |
54 |
| - /// let array = array![[1., 2.], [3., 4.]]; |
55 |
| - /// assert_eq!(array.nrows(), 2usize); |
| 53 | + /// use ndarray::{array, Axis}; |
| 54 | + /// |
| 55 | + /// let array = array![[1., 2.], |
| 56 | + /// [3., 4.], |
| 57 | + /// [5., 6.]]; |
| 58 | + /// assert_eq!(array.nrows(), 3); |
| 59 | + /// |
| 60 | + /// // equivalent ways of getting the dimensions |
| 61 | + /// // get nrows, ncols by using dim: |
| 62 | + /// let (m, n) = array.dim(); |
| 63 | + /// assert_eq!(m, array.nrows()); |
| 64 | + /// // get length of any particular axis with .len_of() |
| 65 | + /// assert_eq!(m, array.len_of(Axis(0))); |
56 | 66 | /// ```
|
57 | 67 | pub fn nrows(&self) -> usize {
|
58 | 68 | self.len_of(Axis(0))
|
@@ -94,9 +104,19 @@ where
|
94 | 104 | /// Return the number of columns (length of `Axis(1)`) in the two-dimensional array.
|
95 | 105 | ///
|
96 | 106 | /// ```
|
97 |
| - /// use ndarray::array; |
98 |
| - /// let array = array![[1., 2.], [3., 4.]]; |
99 |
| - /// assert_eq!(array.ncols(), 2usize); |
| 107 | + /// use ndarray::{array, Axis}; |
| 108 | + /// |
| 109 | + /// let array = array![[1., 2.], |
| 110 | + /// [3., 4.], |
| 111 | + /// [5., 6.]]; |
| 112 | + /// assert_eq!(array.ncols(), 2); |
| 113 | + /// |
| 114 | + /// // equivalent ways of getting the dimensions |
| 115 | + /// // get nrows, ncols by using dim: |
| 116 | + /// let (m, n) = array.dim(); |
| 117 | + /// assert_eq!(n, array.ncols()); |
| 118 | + /// // get length of any particular axis with .len_of() |
| 119 | + /// assert_eq!(n, array.len_of(Axis(1))); |
100 | 120 | /// ```
|
101 | 121 | pub fn ncols(&self) -> usize {
|
102 | 122 | self.len_of(Axis(1))
|
|
0 commit comments