V
V
Viva88882021-11-22 01:35:04
Python
Viva8888, 2021-11-22 01:35:04

How to find the imaginary and real part of a complex number without .real and .imag?

I have a complex number z = a + bi
I need to get a and b
How can this be done without z.real and z.imag

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexbprofit, 2021-11-22
@BMinhoj

x = str(2-3j)

digits = []

for letter in x:
  if letter.isdigit():
    digits.append(float(letter))

print(digits) # [2.0, 3.0]

A
Andy_U, 2021-11-22
@Andy_U

1. You can write your own micro-module in C / C ++ (see documentation , but it will not be platform-independent.
2. Use the struct module. See an example of how to get the binary representation of a float number. You need to do part of the same for complex (float pairs), and then restore the components individually.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question