@@ -53,6 +53,32 @@ pub type Ix5 = Dim<[Ix; 5]>;
53
53
/// six-dimensional
54
54
pub type Ix6 = Dim < [ Ix ; 6 ] > ;
55
55
/// dynamic-dimensional
56
+ ///
57
+ /// `Vec<Ix>` and `&[usize]` implement `IntoDimension` to produce `IxDyn`;
58
+ /// use them to create arrays with a dynamic number of axes.
59
+ ///
60
+ /// ```
61
+ /// use ndarray::ArrayD;
62
+ ///
63
+ /// // Create a 5 × 6 × 3 × 4 array using the dynamic dimension type
64
+ /// let mut a = ArrayD::<f64>::zeros(vec![5, 6, 3, 4]);
65
+ /// // Create a 1 × 3 × 4 array using the dynamic dimension type
66
+ /// let mut b = ArrayD::<f64>::zeros(vec![1, 3, 4]);
67
+ ///
68
+ /// // We can use broadcasting to add arrays of compatible shapes together:
69
+ /// a += &b;
70
+ ///
71
+ /// // We can index into a, b using fixed size arrays:
72
+ /// a[[0, 0, 0, 0]] = 0.;
73
+ /// b[[0, 2, 3]] = a[[0, 0, 2, 3]];
74
+ ///
75
+ /// // Note: It will panic at runtime if the number of indices given does
76
+ /// // not match the array.
77
+ ///
78
+ /// // We can keep them in the same vector because both the arrays have
79
+ /// // the same type `Array<f64, IxDyn>` a.k.a `ArrayD<f64>`:
80
+ /// let arrays = vec![a, b];
81
+ /// ```
56
82
pub type IxDyn = Dim < Vec < Ix > > ;
57
83
58
84
/// zero-dimensional array
0 commit comments