1717 /// Return an array view of row `index`.
1818 ///
1919 /// **Panics** if `index` is out of bounds.
20+ ///
21+ /// ```
22+ /// use ndarray::array;
23+ /// let array = array![[1., 2.], [3., 4.]];
24+ /// assert_eq!(array.row(0), array![1., 2.]);
25+ /// ```
2026 pub fn row ( & self , index : Ix ) -> ArrayView1 < ' _ , A >
2127 where
2228 S : Data ,
2733 /// Return a mutable array view of row `index`.
2834 ///
2935 /// **Panics** if `index` is out of bounds.
36+ ///
37+ /// ```
38+ /// use ndarray::array;
39+ /// let mut array = array![[1., 2.], [3., 4.]];
40+ /// array.row_mut(0)[1] = 5.;
41+ /// assert_eq!(array, array![[1., 5.], [3., 4.]]);
42+ /// ```
3043 pub fn row_mut ( & mut self , index : Ix ) -> ArrayViewMut1 < ' _ , A >
3144 where
3245 S : DataMut ,
3548 }
3649
3750 /// Return the number of rows (length of `Axis(0)`) in the two-dimensional array.
51+ ///
52+ /// ```
53+ /// use ndarray::array;
54+ /// let array = array![[1., 2.], [3., 4.]];
55+ /// assert_eq!(array.nrows(), 2usize);
56+ /// ```
3857 pub fn nrows ( & self ) -> usize {
3958 self . len_of ( Axis ( 0 ) )
4059 }
4867 /// Return an array view of column `index`.
4968 ///
5069 /// **Panics** if `index` is out of bounds.
70+ ///
71+ /// ```
72+ /// use ndarray::array;
73+ /// let array = array![[1., 2.], [3., 4.]];
74+ /// assert_eq!(array.column(0), array![1., 3.]);
75+ /// ```
5176 pub fn column ( & self , index : Ix ) -> ArrayView1 < ' _ , A >
5277 where
5378 S : Data ,
5883 /// Return a mutable array view of column `index`.
5984 ///
6085 /// **Panics** if `index` is out of bounds.
86+ ///
87+ /// ```
88+ /// use ndarray::array;
89+ /// let mut array = array![[1., 2.], [3., 4.]];
90+ /// array.column_mut(0)[1] = 5.;
91+ /// assert_eq!(array, array![[1., 2.], [5., 4.]]);
92+ /// ```
6193 pub fn column_mut ( & mut self , index : Ix ) -> ArrayViewMut1 < ' _ , A >
6294 where
6395 S : DataMut ,
6698 }
6799
68100 /// Return the number of columns (length of `Axis(1)`) in the two-dimensional array.
101+ ///
102+ /// ```
103+ /// use ndarray::array;
104+ /// let array = array![[1., 2.], [3., 4.]];
105+ /// assert_eq!(array.ncols(), 2usize);
106+ /// ```
69107 pub fn ncols ( & self ) -> usize {
70108 self . len_of ( Axis ( 1 ) )
71109 }
@@ -77,6 +115,20 @@ where
77115 }
78116
79117 /// Return true if the array is square, false otherwise.
118+ ///
119+ /// # Examples
120+ /// Sqaure:
121+ /// ```
122+ /// use ndarray::array;
123+ /// let array = array![[1., 2.], [3., 4.]];
124+ /// assert!(array.is_square());
125+ /// ```
126+ /// Not sqaure:
127+ /// ```
128+ /// use ndarray::array;
129+ /// let array = array![[1., 2., 5.], [3., 4., 6.]];
130+ /// assert!(!array.is_square());
131+ /// ```
80132 pub fn is_square ( & self ) -> bool {
81133 self . nrows ( ) == self . ncols ( )
82134 }
0 commit comments