complex-numbers

How should I multiply scipy.fftpack output vectors together?

佐手、 提交于 2020-06-12 06:24:37
问题 The scipy.fftpack.rfft function returns the DFT as a vector of floats, alternating between the real and complex part. This means to multiply to DFTs together (for convolution) I will have to do the complex multiplication "manually" which seems quite tricky. This must be something people do often - I presume/hope there is a simple trick to do this efficiently that I haven't spotted? Basically I want to fix this code so that both methods give the same answer: import numpy as np import scipy

How to use a C function with complex types in Python?

情到浓时终转凉″ 提交于 2020-05-23 10:32:45
问题 I decided to port some of my Python functions to C, mostly following this simple tutorial. Problem is that my C function returns a complex float, and there's no corresponding type in ctypes's documentation. This is is a problem I couldn't solve myself with my limited knowledge on cross-language coding and C, even extended by Google. My C function works like this: #include <tgmath.h> float _Complex integrand(float _Complex theta1, double r, double z){ //[code] } So, based on the tutorial, the

How does tf.gradients manages complex functions?

徘徊边缘 提交于 2020-03-22 03:49:06
问题 I am working with complex-valued neural networks. For Complex-valued neural networks Wirtinger calculus is normally used. The definition of the derivate is then (take into acount that functions are non-Holomorphic because of Liouville's theorem): If you take Akira Hirose book "Complex-Valued Neural Networks: Advances and Applications", Chapter 4 equation 4.9 defines: Where the partial derivative is also calculated using Wirtinger calculus of course. Is this the case for tensorflow? or is it

Square root of complex numbers in python

早过忘川 提交于 2020-01-23 04:30:06
问题 I have run across some confusing behaviour with square roots of complex numbers in python. Running this code: from cmath import sqrt a = 0.2 b = 0.2 + 0j print(sqrt(a / (a - 1))) print(sqrt(b / (b - 1))) gives the output 0.5j -0.5j A similar thing happens with print(sqrt(-1 * b)) print(sqrt(-b)) It appears these pairs of statements should give the same answer? 回答1: Both answers ( +0.5j and -0.5j ) are correct, since they are complex conjugates -- i.e. the real part is identical, and the

af::array::device doesn't work with complex arrays

£可爱£侵袭症+ 提交于 2020-01-17 18:24:12
问题 I just want to "use" a complex af::array for a Cuda kernel. Unfortunately, the transformation which is described in the af documentation (http://arrayfire.org/docs/interop_cuda.htm) doesn't work here: #include <arrayfire.h> #include <af/cuda.h> #include <thrust/complex.h> #include <cuComplex.h> using namespace af; typedef thrust::complex<double> D2; void test(){ randomEngine en = randomEngine(); dim4 dims(4, 4); array a = randn(dims, c64, en); // array a = randn(dims, f64, en); a.eval(); D2

How to avoid the multiple use of 'isnan' to filter inconsitent datasets?

不打扰是莪最后的温柔 提交于 2020-01-16 13:22:26
问题 I have two corresponded (has a relation and has the same dimension) dataset: Time Salinity Some data in salinity dataset is NaN. I can remove the NaN value by: Salinity_new=Salinity(~isnan(Salinity)) But it will not correspond to the Time dataset any more. How can I remove the corresponded time in also? Thanks 回答1: The comments of Diavakar and patrik are correct. To sum it up and get this question answered, some further remarks. mask = isfinite(Salinity) [Time,Salinity] = deal( Time(mask),

How to avoid the multiple use of 'isnan' to filter inconsitent datasets?

混江龙づ霸主 提交于 2020-01-16 13:21:29
问题 I have two corresponded (has a relation and has the same dimension) dataset: Time Salinity Some data in salinity dataset is NaN. I can remove the NaN value by: Salinity_new=Salinity(~isnan(Salinity)) But it will not correspond to the Time dataset any more. How can I remove the corresponded time in also? Thanks 回答1: The comments of Diavakar and patrik are correct. To sum it up and get this question answered, some further remarks. mask = isfinite(Salinity) [Time,Salinity] = deal( Time(mask),

How Can I Plot a Complex Function With Phase Information in MATLAB With Brightness

吃可爱长大的小学妹 提交于 2020-01-14 05:53:29
问题 I need to plot a complex function with phase information in MATLAB. To do this I have ploted a surf plot with x,y representing real and imaginary, the height representing the magnitude and colour depending on the phase, as shown below for the example of log(x): xmin=-5; xmax=5; dx=0.1; xReal = xmin:dx:xmax; xImaginary = xmin:dx:xmax; [x,y] = meshgrid(xReal, xImaginary); s = x + 1i*y; z=log(s); magnitude = abs(z1); Phase = angle(z); figure; h(1) = surf(x,y,magnitude,Phase,'EdgeColor','none');