SciPy is an open-source Python-based library that helps in mathematics, engineering, technical, and scientific computing. SciPy packages are generally needed for scientific computing. The primary reason for using Scipy is its optimization for compute-intensive operations. It can work with NumPy arrays, as SciPy is built on top of NumPy. To install the package, you can run the command mentioned below:
pip install scipy
We will explore the five most commonly used functions from the SciPy package:
cbrt()
: The cbrt() function gets the cube root of a number. It accepts one parameter, i.e., the number whose cube root needs to be determined. The parameter could be a single real number or a list of real numbers. It returns the cube root of the number.exp10()
: The exp10() function calculates the value of the expressions 10x, where x is the input parameter to the given function. The value of x could be any real number or a list containing the real numbers.comb()
: The comb() function calculates the value of the expression xCy. This is the calculation of the number of ways we can select the objects with no effect on the order of the objects. Mathematically, it is termed as combinations. This function accepts two parameters— the value of x and y— and returns the result of the combination.perm()
: The perm() function calculates xPy’s value. This is the calculation of the number of ways we can select y objects out of x. Here, the order of the objects matters. Mathematically, it is termed as permutations. This function accepts two parameters— the value of x and y— and returns the result of the permutation.round()
: The round() function returns the nearest possible integer from the given floating number. For example, if the input given is 1.9, the nearest integer would be 2. This function accepts a real number or a list containing the real numbers.Let’s explore how this works in the code:
import numpyfrom scipy import special#Create a numpy arrayx = numpy.array([27,45])#Get cube rootprint(special.cbrt(x))#Exponential functionprint(special.exp10(x))#Permutation and combinationprint(special.comb(3,2)) #Equivalent to 3C2print(special.perm(3,2)) #Equivalent to 3P2#round functionprint(special.round([1.9, -2.4, 1.2]))
numpy
array.cbrt()
function to get the cube root of the numbers.exp10()
function to get the exponential value.comb()
and the perm()
function to calculate the combination and permutation values, respectively.round()
function to round off the values to the nearest integer.