- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compute the square root of complex inputs with scimath in Python
To compute the square root of input, use the emath.sqrt() method in Python Numpy. The method returns the square root of x. If x was a scalar, so is out, otherwise an array is returned. The parameter x is the input value. For negative input elements, a complex value is returned
Steps
At first, import the required libraries −
import numpy as np
The complex input explicity using complex() method −
a = complex(-9.0, 0.0)
Display the array −
print("Display the complex value...\n",a)
To compute the square root of input, use the emath.sqrt() method in Python Numpy −
print("\nResult...\n",np.emath.sqrt(a))
Example
import numpy as np # Explicity using complex() method a = complex(-9.0, 0.0) # Display the array print("Display the complex value...\n",a) # To compute the square root of input, use the emath.sqrt() method in Python Numpy # The method returns the square root of x. If x was a scalar, so is out, otherwise an array is returned. print("\nResult...\n",np.emath.sqrt(a))
Output
Display the complex value... (-9+0j) Result... 3j
Advertisements