Skip to content

Commit 9832287

Browse files
committed
Edit dimension docs
1 parent 4f8847e commit 9832287

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,29 +217,36 @@ pub type Ixs = isize;
217217
///
218218
/// ## Indexing and Dimension
219219
///
220-
/// Array indexes are represented by the types `Ix` and `Ixs` (signed).
221-
///
222220
/// The dimensionality of the array determines the number of *axes*, for example
223221
/// a 2D array has two axes. These are listed in “big endian” order, so that
224222
/// the greatest dimension is listed first, the lowest dimension with the most
225223
/// rapidly varying index is the last.
226224
///
227-
/// In a 2D array the index of each element is `(row, column)`
228-
/// as seen in this 3 × 3 example:
225+
/// In a 2D array the index of each element is `[row, column]` as seen in this
226+
/// 4 × 3 example:
229227
///
230228
/// ```ignore
231-
/// [[ (0, 0), (0, 1), (0, 2)], // row 0
232-
/// [ (1, 0), (1, 1), (1, 2)], // row 1
233-
/// [ (2, 0), (2, 1), (2, 2)]] // row 2
229+
/// [[ [0, 0], [0, 1], [0, 2] ], // row 0
230+
/// [ [1, 0], [1, 1], [1, 2] ], // row 1
231+
/// [ [2, 0], [2, 1], [2, 2] ], // row 2
232+
/// [ [3, 0], [3, 1], [3, 2] ]] // row 3
234233
/// // \ \ \
235234
/// // column 0 \ column 2
236235
/// // column 1
237236
/// ```
238237
///
239-
/// The number of axes for an array is fixed by the `D` parameter: `Ix` for
240-
/// a 1D array, `(Ix, Ix)` for a 2D array etc. The `D` type is also used
241-
/// for element indices in `.get()` and `array[index]`. The dimension type `Vec<Ix>`
242-
/// allows a dynamic number of axes.
238+
/// The number of axes for an array is fixed by its `D` type parameter: `Ix1`
239+
/// for a 1D array, `Ix2` for a 2D array etc. The dimension type `IxDyn` allows
240+
/// a dynamic number of axes.
241+
///
242+
/// An array of the corresponding dimensionality is used to index the array,
243+
/// making the syntax `array[[` i, j, ...`]]`
244+
///
245+
/// ```
246+
/// use ndarray::Array2;
247+
/// let mut array = Array2::zeros((4, 3));
248+
/// array[[1, 1]] = 7;
249+
/// ```
243250
///
244251
/// The default memory order of an array is *row major* order (a.k.a “c” order),
245252
/// where each row is contiguous in memory.

0 commit comments

Comments
 (0)