0

I have been building math tools in Python without numpy and am wondering if I have to use numpy to do more than add and subtract using the complex numbers built into Python.

I've tried just plugging the complex command into my functions, for example:

import math

def f(a, b):
    return math.cos(complex(a, b))

print(f(1, 1))

and it won't calculate it.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 1
    Does this answer your question? [Complex numbers in python](https://stackoverflow.com/questions/8370637/complex-numbers-in-python) – mkrieger1 May 14 '23 at 20:49

1 Answers1

1

The cmath module provides complex number variants of the math module functions:

>>> import cmath
>>> z = 3 + 4j
>>> cmath.sqrt(z)
(2+1j)
>>> cmath.cos(z) (-27.034945603074224-3.8511533348117775j)
Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485