3

I am trying to make a real number complex using numpy. I am using numpy version 1.24.3

Here is the code:

import numpy as np
c=np.complex(1)

However, I get this error:

AttributeError: module 'numpy' has no attribute 'complex'.
Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
  • Similar to [How can I solve error "module 'numpy' has no attribute 'float'" in Python?](https://stackoverflow.com/questions/74844262/how-can-i-solve-error-module-numpy-has-no-attribute-float-in-python) – mozway May 25 '23 at 09:17

1 Answers1

4

np.complex was a deprecated alias for the builtin complex.

Instead of np.complex you can use:

complex(1)         #output (1+0j)

#or

np.complex128(1)   #output (1+0j)

#or

np.complex_(1)     #output (1+0j)

#or

np.cdouble(1)      #output (1+0j)

Link to doc: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44