complex-numbers

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

廉价感情. 提交于 2019-12-10 02:56:22
问题 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() <

statistics for histogram of periodic data

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 20:07:35
问题 For a series of angle values in (-pi, pi) range, I make a histogram. Is there an effective way to calculate a mean and modal (post probable) value? Consider following examples: import numpy as N, cmath deg = N.pi/180. d = N.array([-175., 170, 175, 179, -179])*deg i = N.sum(N.exp(1j*d)) ave = cmath.phase(i) i /= float(d.size) stdev = -2. * N.log(N.sqrt(i.real**2 + i.imag**2)) print ave/deg, stdev/deg Now, let's have a histogram: counts, bins = N.histogram(data, N.linspace(-N.pi, N.pi, 360)) Is

C++ operator overloading for complex number operations

假如想象 提交于 2019-12-08 19:48:01
问题 I have an assignment in C++ and I'm having trouble getting started. The goal is to "design a class that uses the following overloaded operators for complex numbers: >> << + - * / " My question isn't about the syntax of this, but more about the logic. I could use some help brain storming. Input Sample: 2.5 -2.2 1.0 1.0 OutPut Sample: A = (2.5) + (-2.2)i B = (1.0) + (1.0)i A + B = (3.5) + (-1.2)i A - B = .............. A * B = .............. A / B = .............. So how do I start this? The

Homework Help Pt2 (Math The Complex Class)

半腔热情 提交于 2019-12-08 06:56:58
问题 Not sure if I'm doing this right, but this is a continuation of the program I was working on here...Homework Help PT1 I'm struggling a lot with this homework assignment... **(Math: The Complex class) A complex number is a number in the form a + bi, where a and b are real numbers and i is 2-1. The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the

c++ display complex number with i in imaginary part

左心房为你撑大大i 提交于 2019-12-08 06:52:38
问题 I am doing something like: int real_part, imaginary_part; cout<<"Please enter realpart and imaginary part"<<endl; cin>>real_part; cin>>imaginary_part; complex<double> mycomplex (real_part, imaginary_part); cout<<mycomplex<<endl; // I want to display like -2+5i but I get (-2, 5) I am very new to c++ How can I display with i like -2+5i ? Or I have to add i char with imagginary part ? 回答1: You can use std::real() and std::imag() to format as you like, see complex here. Of course, you will have

loading complex numbers with numpy.loadtxt

微笑、不失礼 提交于 2019-12-07 23:44:56
问题 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,

How to get Vector of Complex numbers from two vectors (real & imag)

独自空忆成欢 提交于 2019-12-07 17:48:27
I have two vectors of floats and i want them to become one vector of Complex numbers. I'm stuck. I don't mind using iterators, but i am sure it'd be rediscovering the wheel i'm not informed about. Is my code leading me in the right direction? typedef std::vector<float> CVFloat; CVFloat vA, vB; //fil vectors typedef std::complex<CVFloat> myComplexVector; myComplexVector* vA_Complex = new myComplexVector(vA, vB); The code above is going through the compiler correctly, but when i want to get single numbers from myComplexVector using iterator i get error "Undefined symbol 'const_iterator'"

Complex convolution in tensorflow

青春壹個敷衍的年華 提交于 2019-12-07 15:41:11
问题 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

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

别来无恙 提交于 2019-12-07 11:09:16
问题 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? 回答1: 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-07 10:40:42
问题 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