ID : 355

viewed : 191

Tags : PythonPython Math

99

The nth root, which is used in multiplication, gives us the basic and original value. But what is nth root? Rather than writing the 4th, 16th, etc, we can just say the n-th.

- The second root is the square root
- The third root is the cube root
- etc!

This article will introduce how to obtain the nth root of x value by using the numpy built-in library and the other method without using the numpy library in Python. Below will give a brief description of how to obtain the nth root of any number with or without the library.

Here we are about to find square root through , also when we want to find the cube of a number, we use the same built-in `numpy.cbrt()`

. But what if we want to find the 4th root or 8th root of a number? Then you have to use the specific equation with built-in power function in Python, which is described below precisely.

At the same time, we are working with the power and also root in Python. Fortunately, there’s a built-in way of making it troubleless: the Python `numpy`

module.

Here we will show how we can import the `numpy`

module from the built-in Python module. After that we will deal with some Python built-in functions to find the root of a specific number in Python.

You will also find below some examples of finding the specific root of a number using the built-in functions and using expressions without functions.

`power()`

FunctionStarting the procedure, we will first import the `numpy`

module; then, we will assign the two values to find the root of a value, respectively. Then using the built-in power function, we will find the 2nd root of value 9. The result value will be displayed in the output.

Example codes:

`# python 3.x import numpy as npobject a = 9 n = 2 result=(npobject.power(a,(1/n))) print(f'The {n}th root of value = {a} is:',result) `

Output:

`The 2th root of value = 9 is: 3.0 `

This code block will not import the numpy built-in module because we will use the Python expression to find the root of any value. First, we will assign the two values to find the root of a value, respectively. We then use the equation to find the 2nd root of value 9. In general, we can easily find the nth root of x value without using the built-in function.

The syntax for finding the nth root of x is :

`x**(1/float(n) `

The result value will be displayed in the output.

Example codes:

`# python 3.x x = 9 n = 2 result=x**(1/float(n)) print(f'The {n}th root of value = {x} is:',result) `

Output:

`The 2th root of value = 9 is: 3.0 `