Compute the square root of negative input with emath in Python Last Updated : 01 May, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will cover how to compute the square root of negative inputs with emath in Python using NumPy. Example:Input: [-3,-4] Output: [0.+1.73205081j 0.+2.j ] Explanation: Square root of a negative input.NumPy.emath.sqrt method: The np.emath.sqrt() method from the NumPy library calculates the square root of complex inputs. A complex value is returned for negative input elements unlike numpy.sqrt. which returns NaN. Syntax: np.emath.sqrt() Parameters: x: array like object. Return: out: scalar or ndarray. Example 1: If the array contains negative input values, complex numbers are returned in the output, and the shape, datatype, and dimensions of the array can be found by .shape, .dtype, and .ndim attributes. Python3 import numpy as np # Creating an array arr = np.array([-3, -4]) print(array) # shape of the array is print("Shape of the array is : ",arr.shape) # dimension of the array print("The dimension of the array is : ",arr.ndim) # Datatype of the array print("Datatype of our Array is : ",arr.dtype) # computing the square root of negative inputs print(np.emath.sqrt(arr)) Output: [-3 -4] Shape of the array is : (2,) The dimension of the array is : 1 Datatype of our Array is : int64 [0.+1.73205081j 0.+2.j ]Example 2: Python3 import numpy as np # Creating an array array = np.arr([complex(-2, -1),complex(-5, -3)]) print(array) # shape of the array is print("Shape of the array is : ",arr.shape) # dimension of the array print("The dimension of the array is : ",arr.ndim) # Datatype of the array print("Datatype of our Array is : ",arr.dtype) # computing the square root of complex inputs print(np.emath.sqrt(arr)) Output: [-2.-1.j -5.-3.j] Shape of the array is : (2,) The dimension of the array is : 1 Datatype of our Array is : complex128 [0.34356075-1.45534669j 0.64457424-2.32711752j] Comment More infoAdvertise with us Next Article Compute the square root of negative input with emath in Python I isitapol2002 Follow Improve Article Tags : Python Python-numpy Python numpy-Mathematical Function Practice Tags : python Similar Reads Compute the square root of complex inputs with scimath in Python In this article, we will cover how to compute the square root of complex inputs with scimath in Python using NumPy. ExampleInput: [-1 -2] Output: [0.+1.j 0.+1.41421356j] Explanation: Square root of complex input.NumPy.emath.sqrt method The np.emath.sqrt() method from the NumPy library calculates the 2 min read How to get a negative out of a square root? Complex numbers are those numbers that are composed of two parts Real part + Imaginary part. For the complex number x = a + ib, a is called the real part, and b is called the imaginary part. Imaginary numbers are those numbers whose square root is a negative number. Examples - 7 + 4i, 5 + 2i, 2 - 2i 5 min read Compute the inverse sine with scimath using NumPy in Python In this article, we will cover how to compute the inverse sine with scimath in Python. np.emath.arcsin method A NumPy array can be created in different ways like, by various numbers, and by defining the size of the Array. It can also be created with the use of various data types such as lists, tuple 2 min read How to perform modulo with negative values in Python? Taking the modulo of a negative number is a bit more complex mathematics which is done behind the program of Python. If we don't understand the mathematics behind the modulo of negative numbers then it will become a huge blunder. Mathematics behind the negative modulo :Let's Consider an example, whe 3 min read Compute the logarithm base n with scimath in Python In this article, we will be looking at the approach to computing the logarithm base n with scimath in Python. The NumPy package provides us the numpy.lib.scimath.logn() method to compute the logarithmic base n. the method takes log base n of x. Let's check the syntax to know the method better. The s 2 min read Like