Skip to content

Commit 8f6c33d

Browse files
committed
add method to produce view with swapped axes
1 parent 41bace1 commit 8f6c33d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/impl_methods.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,27 @@ where
23632363
self.strides.slice_mut().swap(ax, bx);
23642364
}
23652365

2366+
/// Return a view with swapped axes
2367+
///
2368+
/// See also [Self::t] and [Self::reversed_axes].
2369+
///
2370+
/// ```
2371+
/// # use ndarray::*;
2372+
/// let a = array![
2373+
/// [[ 0, 1, 1, 1],[ 2, 3, 3, 3],[ 4, 5, 5, 5]],
2374+
/// [[10,11,11,11],[12,13,13,13],[14,15,15,15]],
2375+
/// ];
2376+
/// assert_eq!(a.dim(), (2,3,4));
2377+
/// assert_eq!(a.swap_axes_view(0, 1).dim(), (3, 2, 4));
2378+
/// ```
2379+
pub fn swap_axes_view(&self, ax: usize, bx: usize) -> ArrayView<'_, A, D>
2380+
where S: Data
2381+
{
2382+
let mut view = self.view();
2383+
view.swap_axes(ax, bx);
2384+
view
2385+
}
2386+
23662387
/// Permute the axes.
23672388
///
23682389
/// This does not move any data, it just adjusts the array’s dimensions

0 commit comments

Comments
 (0)