on-internet
← Community

How can I create a Vec<[f64; 2]> from two Vec of the same length?

Stack Overflow ·

If I have two different Vec<f64> of the same length, how can I "zip" them to get a Vec<[f64; 2]> instead of a Vec<(f64, f64)>? Here Is what I have so far: let vec1: Vec<f64> = vec![1.,2.,3.,4.,5.,6.]; let vec2: Vec<f64> = vec![6.,5.,4.,3.,2.,1.]; let zipped_vec: Vec<(&f64, &f64)> = vec1.iter().zip(vec2.iter()).collect::<Vec<_>>(); println!("{:?}", zipped_vec); // Output: [(1.0, 6.0), (2.0, 5.0), (3.0, 4.0), (4.0, 3.0), (5.0, 2.0), (6.0, 1.0)] // If all the data is in a single Vec<f64> I found a way to do it with "chunks_exact" let data = vec![1.,12.,2.,23.,3.,38.,4.,44.,5.,59.,6.,71.]; let gra

Comments

Sign in or sign up to comment and upvote.

No comments yet.