numpy.roots() function Python (original) (raw)
Last Updated : 11 Jun, 2020
numpy.roots()
function return the roots of a polynomial with coefficients given in p. The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by: p[0] * x**n + p[1] * x**(n-1) + … + p[n-1]*x + p[n]
Syntax : numpy.roots(p)
Parameters :
p : [array_like] Rank-1 array of polynomial coefficients.Return : [ndarray] An array containing the roots of the polynomial.
Code #1 :
import
numpy as geek
p
=
[
1
,
2
,
3
]
gfg
=
geek.roots(p)
print
(gfg)
Output :
[-1.+1.41421356j -1.-1.41421356j]
Code #2 :
import
numpy as geek
p
=
[
3.2
,
2
,
1
]
gfg
=
geek.roots(p)
print
(gfg)
Output :
[-0.3125+0.46351241j -0.3125-0.46351241j]
Similar Reads
- numpy.real() function - Python numpy.real() function return the real part of the complex argument. Syntax : numpy.real(arr) Parameters : arr : [array_like] Input array. Return : [ndarray or scalar] The real component of the complex argument. If val is real, the type of val is used for the output. If val has complex elements, the 1 min read
- numpy.i0() function | Python numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev 1 min read
- round() function in Python Python round() function is a built-in function available with Python. It will return you a float number that will be rounded to the decimal places which are given as input. If the decimal places to be rounded are not specified, it is considered as 0, and it will round to the nearest integer. In this 6 min read
- numpy.sqrt() in Python numpy.sqrt() in Python is a function from the NumPy library used to compute the square root of each element in an array or a single number. It returns a new array of the same shape with the square roots of the input values. The function handles both positive and negative numbers, returning NaN for n 2 min read
- Python | math.sin() function In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.sin() function returns the sine of value passed as argument. The value passed in this function should be in radians. Syntax: math.sin(x) Parameter: x : value to be passed to s 1 min read
- pow() Function - Python pow() function in Python is a built-in tool that calculates one number raised to the power of another. It also has an optional third part that gives the remainder when dividing the result. Example: [GFGTABS] Python print(pow(3,2)) [/GFGTABS]Output9 Explanation: pow(3, 2) calculates 32 = 9, where the 2 min read
- Python int() Function The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part. Example: In this example, we passed a string as an argument to the int() function and printed it. [GFGTABS] Python age = "21" 4 min read
- numpy.cbrt() in Python This mathematical function helps user to calculate cube root of x for all x being the array elements. Syntax: numpy.cbrt(arr, out = None, ufunc ‘cbrt’) : Parameters : arr : [array_like] Input array or object whose elements, we need to square. Return : An array with cube root of x for all x i.e. arra 2 min read
- hypot() function - Python math.hypot() function in Python is used to compute the Euclidean distance from the origin (0, 0) to a point (x, y) in a 2D plane. It calculates the hypotenuse of a right triangle, given the lengths of the two other sides. Example[GFGTABS] Python import math x = 3 y = 4 res = math.hypot(x, y) print(r 4 min read
- numpy.fromstring() function – Python numpy.fromstring() function create a new one-dimensional array initialized from text data in a string. Syntax : numpy.fromstring(string, dtype = float, count = -1, sep = ' ') Parameters : string : [str] A string that contained the data. dtype : [data-type, optional] Data-type of the array. Default d 1 min read