complex-numbers

loading complex numbers with numpy.loadtxt

夙愿已清 提交于 2019-12-06 06:43:36
I know that if I want to save and load arrays of complex numbers with numpy, I can use the method described here: How to save and load an array of complex numbers using numpy.savetxt? . Assume however, that someone did not know about this and saved their array numbers with numpy.savetxt("numbers.txt",numbers ), producing a file with entries of the form (0.000000000000000000e+00+-2.691033635430225765e-02j) . In this case numbers_load = numpy.loadtxt("numbers.txt").view(complex) will, predictably, fail in the sense of ValueError: could not convert string to float: (0.000000000000000000e+00+-2

Complex convolution in tensorflow

牧云@^-^@ 提交于 2019-12-06 03:03:28
I'm trying to run a simple convolution but with complex numbers: r = np.random.random([1,10,10,10]) i = np.random.random([1,10,10,10]) x = tf.complex(r,i) conv_layer = tf.layers.conv2d( inputs=x, filters=10, kernel_size=[3,3], kernel_initializer=utils.truncated_normal_complex(), activation=tf.nn.sigmoid) However I get this error: TypeError: Value passed to parameter 'input' has DataType complex128 not in list of allowed values: float16, float32 Does anyone know how to implement such a convolution in Tensorflow? Will I need to implement a custom op, or is there some better option here?

Finding complex roots from set of non-linear equations in python

旧街凉风 提交于 2019-12-06 01:30:06
问题 I have been testing an algorithm that has been published in literature that involves solving a set of 'm' non-linear equations in both Matlab and Python. The set of non-linear equations involves input variables that contain complex numbers, and therefore the resulting solutions should also be complex. As of now, I have been able to get pretty good results in Matlab by using the following lines of code: lambdas0 = ones(1,m)*1e-5; options = optimset('Algorithm','levenberg-marquardt',...

a function returning reference to real or imag values of a complex number in C++11

最后都变了- 提交于 2019-12-05 14:36:55
I'm looking for a function that returns a reference to real or imag values of a complex number in C++11. In C++03 I could say: complex<double> C; cin >> C.real(); But in C++11 that gives me a compile error since the C.real() returns a value not a reference. I found out that I can write this: double t; cin >> t; C.real(t); but it isn't straightforward and for example if I want to multiply the real part of c by 2 and ad it by 1 I should say: C.real(2*C.real() + 1); That is not clean. Is there any other [clean] way to do that? Sorry to be negative, but your question starts from a wrong premise.

How can I plot a function in R with complex numbers?

谁说我不能喝 提交于 2019-12-05 14:34:42
I want to plot the following function in R f(w) = 1/(1-5*e^(-iw)) where i is the square root of -1. Can R handle complex numbers in plotting? This should get you started (mostly by demonstrating the notation R uses for representing complex numbers and the exponential function). f <- function(x) 1/(1-5*exp(-(0+1i)*x)) x <- seq(0, 2*pi, by=0.1) plot(f(x)) 来源: https://stackoverflow.com/questions/20109257/how-can-i-plot-a-function-in-r-with-complex-numbers

Does Chicken Scheme support complex numbers? If so, why am I getting this error?

只谈情不闲聊 提交于 2019-12-05 13:31:36
I just started learning a little Scheme, and I'm using Dorai Sitaram's Teach Yourself Scheme in Fixnum Days . In said work it is stated: Scheme numbers can be integers (eg, 42) ... or complex ( 2+3i ). Emphasis mine. Note the form. Using the principles I had been taught so far I tried writing a few different programs that dealt with the different kinds of numbers. I ended up writing this extremely simple snippet to test complex numbers: (begin (display 3+4i) (newline) ) Testing this on codepad.org (which uses MzScheme) and Ideone.com (which uses guile) worked perfectly. Now, when I tried it

Does ICC satisfy C99 specs for multiplication of complex numbers?

倖福魔咒の 提交于 2019-12-05 10:58:32
问题 Consider this simple code: #include <complex.h> complex float f(complex float x) { return x*x; } If you compile it with -O3 -march=core-avx2 -fp-model strict using the Intel Compiler you get: f: vmovsldup xmm1, xmm0 #3.12 vmovshdup xmm2, xmm0 #3.12 vshufps xmm3, xmm0, xmm0, 177 #3.12 vmulps xmm4, xmm1, xmm0 #3.12 vmulps xmm5, xmm2, xmm3 #3.12 vaddsubps xmm0, xmm4, xmm5 #3.12 ret This is much simpler code than you get from both gcc and clang and also much simpler than the code you will find

How to round up a complex number?

こ雲淡風輕ζ 提交于 2019-12-05 10:28:58
How can I round up a complex number (e.g. 1.9999999999999998-2j ) as 2-2j ? When I tried using print(round(x,2)) it showed Traceback (most recent call last): File "C:\Python34\FFT.py", line 22, in <module> print(round(x,2)) TypeError: type complex doesn't define __round__ method Round real part and imaginary part separately and combine them: >>> num = 1.9999999999999998-2j >>> round(num.real, 2) + round(num.imag, 2) * 1j (2-2j) If all you want to do is represent the value rounded as shown, rather than modify the value itself, the following works: >>> x=1.9999999999999998-2j >>> print("{:g}"

Complex type with C linkage in C++11

我们两清 提交于 2019-12-05 09:42:49
I need to include the header of a C library into my C++11 code. Now, the header provides routines and data structures that involve plenty of double complex all over the place. E.g., #include <complex.h> //.. typedef struct parameters { // ... double complex Vud; } parameters; // ... double complex polylog(int n, int m, double x); I bring this file into my C++11 source wrapped in extern "C" { #include "include.h" } (that's the actual filename, believe it or not). And g++ (tried 4.7.3 and 4.8.2) and clang (3.3) go nuts if I have -std=c++11 added. The millions of lines of g++ errors include

Why does this key class for sorting heterogeneous sequences behave oddly?

六眼飞鱼酱① 提交于 2019-12-05 02:59:58
Python 3.x's sorted() function cannot be relied on to sort heterogeneous sequences, because most pairs of distinct types are unorderable (numeric types like int , float , decimal.Decimal etc. being an exception): Python 3.4.2 (default, Oct 8 2014, 08:07:42) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> sorted(["one", 2.3, "four", -5]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: float() < str() In contrast, comparisons between objects that have no natural order are arbitrary but consistent