rot90 function? #866
Description
Activity
I have it like this, but something built-in would be nice:
fn rot90(arr: &Array2<u32>) -> Array2<u32> { arr.t().dot(&Array2::eye(arr.nrows()).slice(s![..,..;-1])) }Fwiw, it's possible to implement the default case (2-D, 90 deg counterclockwise) in a somewhat simpler way:
use ndarray::{array, ArrayBase, Axis, Ix2, RawData}; fn rot90<S>(arr: &mut ArrayBase<S, Ix2>) where S: RawData, { arr.swap_axes(0, 1); arr.invert_axis(Axis(0)); } fn main() { let mut a = array![[1, 2, 3], [4, 5, 6]]; println!("before:\n{}", a); rot90(&mut a); println!("after:\n{}", a); }
This doesn't copy the data; it just modifies the shape and strides.
(If you don't want to modify the original array, you could clone it before calling
rot90, or callrot90on a view of the array.)I agree that it would be worthwhile to add an equivalent to NumPy's
rot90(including the optional parameters) just to simplify things for users and help users port code, even though sequences ofswap_axesandinvert_axiscan accomplish the same thing for specific values of the optional parameters.Would someone be interested in implementing an equivalent to NumPy's
rot90function?Reacted by bluss and Сергей ГришаковThanks, because the function signature I have there does not work and I have no clue to fix it when I get an error message (forthcoming, from the other laptop).
I'm looking around, but is there really no
rot90function on a square array?