17
17
/// Return an array view of row `index`.
18
18
///
19
19
/// **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
+ /// ```
20
26
pub fn row ( & self , index : Ix ) -> ArrayView1 < ' _ , A >
21
27
where
22
28
S : Data ,
27
33
/// Return a mutable array view of row `index`.
28
34
///
29
35
/// **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
+ /// ```
30
43
pub fn row_mut ( & mut self , index : Ix ) -> ArrayViewMut1 < ' _ , A >
31
44
where
32
45
S : DataMut ,
35
48
}
36
49
37
50
/// 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
+ /// ```
38
57
pub fn nrows ( & self ) -> usize {
39
58
self . len_of ( Axis ( 0 ) )
40
59
}
48
67
/// Return an array view of column `index`.
49
68
///
50
69
/// **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
+ /// ```
51
76
pub fn column ( & self , index : Ix ) -> ArrayView1 < ' _ , A >
52
77
where
53
78
S : Data ,
58
83
/// Return a mutable array view of column `index`.
59
84
///
60
85
/// **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
+ /// ```
61
93
pub fn column_mut ( & mut self , index : Ix ) -> ArrayViewMut1 < ' _ , A >
62
94
where
63
95
S : DataMut ,
66
98
}
67
99
68
100
/// 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
+ /// ```
69
107
pub fn ncols ( & self ) -> usize {
70
108
self . len_of ( Axis ( 1 ) )
71
109
}
@@ -77,6 +115,20 @@ where
77
115
}
78
116
79
117
/// 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
+ /// ```
80
132
pub fn is_square ( & self ) -> bool {
81
133
self . nrows ( ) == self . ncols ( )
82
134
}
0 commit comments