complex-numbers

Why is the integration not progressing with scipy.integrate.ode?

Why is the integration not progressing with scipy.integrate.ode? Question: I am integrating a function func in the complex domain using scipy.integrate.ode. I have assembled the following code structure: import numpy as np from scipy.integrate import ode def func(x, u, k): #f, g = u dfdx = k*x**2 dgdx = -x rhs_FD = [0]*2 rhs_FD[0] = …

Total answers: 1

What is the benefit of using complex numbers to store graph coordinates?

What is the benefit of using complex numbers to store graph coordinates? Question: I am looking at a solution to an Advent of Code puzzle that stores coordinates as complex numbers: heightmap = { complex(x, y): c for y, ln in enumerate(sys.stdin.read().strip().split("n")) for x, c in enumerate(ln) } Then accesses them later as follows: for …

Total answers: 1

How to make 2d complex number array in numpy?

How to make 2d complex number array in numpy? Question: I would like to make a 2d array of even distribution of complex numbers, a part of complex plane, for example (-1, 1i), (-1, -1i), (1, 1i), (1, -1i) with 20 numbers in each dimension. I know I can do this for complex numbers in …

Total answers: 2

Splitting a dataframe with complex numbers into real and imaginary numbers with python

Splitting a dataframe with complex numbers into real and imaginary numbers with python Question: I would like to split the following complex dataframe into two columns, df = pd.DataFrame({"AB": [‘0.316227766016838-0.316227766016838i’, ‘0.316227766016838-0.316227766016838i’, ‘0.316227766016838-0.316227766016838i’, ‘0.316227766016838-0.316227766016838i’, ‘0.316227766016838+0.316227766016838i’, ‘0.3162277660168380+.316227766016838i’]}) I tried in the following way but it works either for – or + df1=df[‘AB’].str.split(‘-‘, n=1, expand=True) How can I …

Total answers: 1

Why is log(inf + inf j) equal to (inf + 0.785398 j), In C++/Python/NumPy?

Why is log(inf + inf j) equal to (inf + 0.785398 j), In C++/Python/NumPy? Question: I’ve been finding a strange behaviour of log functions in C++ and numpy about the behaviour of log function handling complex infinite numbers. Specifically, log(inf + inf * 1j) equals (inf + 0.785398j) when I expect it to be (inf …

Total answers: 4

Problem using numpy to obtain the complex conjugate of a matrix

Problem using numpy to obtain the complex conjugate of a matrix Question: I have the following code: import numpy as np A=np.array([[2, 2-9j, -5j], [4-1j, 0, 9+6j], [4j, 6+7j, 6]]) print(A) print(A.getH()) It doesn’t work. I have checked different webs and followed this webpage (geeksforgeeks), and this other(official numpy documentation) but I still get an …

Total answers: 3

How to perform approximate structural pattern matching for floats and complex

How to perform approximate structural pattern matching for floats and complex Question: I’ve read about and understand floating point round-off issues such as: >>> sum([0.1] * 10) == 1.0 False >>> 1.1 + 2.2 == 3.3 False >>> sin(radians(45)) == sqrt(2) / 2 False I also know how to work around these issues with math.isclose() …

Total answers: 2

Regular expression for complex numbers

Regular expression for complex numbers Question: So I’am trying to write regular expression for complex numbers (just as an exercise to study re module). But I can’t get it to work. I want regex to match strings of form: ’12+18j’, ‘-14+45j’, ’54’, ‘-87j’ and so on. My attempt: import re num = r'[+-]?(?:d*.d+|d+)’ complex_pattern = …

Total answers: 4