Using element-wise power in ndarray with num_complex::Complex64

ndarray::ArrayBase's pow2, for example, does not work on num_complex::Complex64(trait bound Float).

The code I was trying to compile was like:

let array = array!(Complex64::new(1.0, 2.0));
let array_pow = array.pow2();

Can I get some guidance on how to use one of the power functions from ndarray on complex types?

I am new here, please excuse me if I posted at the wrong place.

Their pow functions require Float, which Complex doesn't implement because some of the methods don't make sense on complex numbers. You can use array.map(|c| c * c), or |c| c.powi(n) etc.

I see, pow is something that makes sense with complex numbers. What prevents the changing of trait bounds, in ndarray, for just the operations that are meaningful? Is it worth opening an issue for this?

An issue seems fine -- it doesn't hurt to ask, even if they say no.
(though I'd recommend searching past issues first)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.