ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

Inverse of split_complex?

Open JP-Ellis opened this issue 3 years ago • 0 comments
trafficstars

I have recently started using the split_complex function which has been of great help, but I was wondering whether there is a convenience function for constructing a complex array from the real and imaginary parts separately?

Currently, the best I can think of is to use something along the lines of

let re = array![1, 2, 3];
let im = array![10, 20, 30];
let complex = Array1::from_shape_fn(re.dim(), |i| Complex::new(re[i], im[i]));

I have noticed that the split_complex code seems extremely efficient and (I believe it) uses the fact that the Complex<T> type is itself akin to [T; 2]. Might something similar be possible to construct an array more efficiently than through an iterator as above?

JP-Ellis avatar May 18 '22 12:05 JP-Ellis