{"id":28093,"date":"2022-05-30T16:28:33","date_gmt":"2022-05-30T10:58:33","guid":{"rendered":"https:\/\/python-programs.com\/?p=28093"},"modified":"2022-05-30T16:28:33","modified_gmt":"2022-05-30T10:58:33","slug":"how-to-calculate-the-square-root-of-negative-input-with-emath-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/how-to-calculate-the-square-root-of-negative-input-with-emath-in-python\/","title":{"rendered":"How to calculate the Square Root of Negative Input with emath in Python?"},"content":{"rendered":"

Let us see\u00a0how to use NumPy to compute the square root of negative inputs with emath in Python.<\/p>\n

Python numPy.emath.sqrt() Function:<\/strong><\/p>\n

The numpy.emath.sqrt() function of the numpy module is used to\u00a0compute\u00a0the square root of complex inputs. In contrast to numpy.sqrt, which returns NaN for negative input elements, complex values are returned.<\/p>\n

Syntax:<\/strong><\/p>\n

numpy.emath.sqrt()<\/pre>\n

Parameters<\/strong><\/p>\n

x:<\/strong> It is an array-like object given as input.<\/p>\n

Return Value:<\/strong>
\nA scalar value or an ndarray is returned by the numpy.emath.sqrt() function.<\/p>\n

If the array contains negative input values, complex numbers are returned in the output, and the .shape, dtype, and .ndim attributes can be used to determine the array’s shape, datatype, and dimensions respectively.<\/p>\n

Python Program to Calculate the Square Root of Negative Input with emath<\/h2>\n

For Negative Array Values:<\/h3>\n

Approach:<\/strong><\/p>\n