{"id":88793,"date":"2023-12-04T18:00:28","date_gmt":"2023-12-04T12:30:28","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=88793"},"modified":"2023-12-04T18:00:28","modified_gmt":"2023-12-04T12:30:28","slug":"numpy-mathematical-functions","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/","title":{"rendered":"NumPy Mathematical Functions"},"content":{"rendered":"<p>In this tutorial, we will explore a variety of mathematical functions that Numpy offers, along with examples demonstrating their usage. Let&#8217;s dive in and see how these functions can enhance your data manipulation and analysis tasks.<\/p>\n<h2>Trigonometric Functions<\/h2>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Function<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">sin(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the sine of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">cos(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the cosine of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">tan(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the tangent of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">arcsin(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the inverse sine (arcsine) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">arccos(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the inverse cosine (arccosine) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">arctan(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the inverse tangent (arctangent) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">hypot(x1, x2, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the hypotenuse of a right triangle given the &#8220;legs&#8221; x1 and x2.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">arctan2(x1, x2, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the arctangent of x1\/x2 with the correct quadrant, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">degrees(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Convert angles from radians to degrees, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">radians(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Convert angles from degrees to radians, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">unwrap(p[, discont, axis, period])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Unwrap an array by complementing large deltas with respect to the specified period.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">deg2rad(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Convert angles from degrees to radians, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">rad2deg(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Convert angles from radians to degrees, element-wise.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Compute Tangent &#8211; numpy.tan()<\/h4>\n<p>The numpy.tan() function computes the tangent of each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, np.pi\/4, np.pi\/2])\n\n# Compute tangent\ntan_values = np.tan(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>tan_values:<\/strong> [0.00000000e+00 1.00000000e+00 1.63312394e+16]<\/p>\n<h4>Inverse Sine &#8211; numpy.arcsin()<\/h4>\n<p>The numpy.arcsin() function calculates the inverse sine (in radians) for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 0.5, 1])\n\n# Compute inverse sine\narcsin_values = np.arcsin(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arcsin_values:<\/strong> [0. 0.52359878 1.57079633]<\/p>\n<h4>Trigonometric Inverse Cosine &#8211; numpy.arccos()<\/h4>\n<p>The numpy.arccos() function calculates the inverse cosine (in radians) for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1, 0.5, 0])\n\n# Compute inverse cosine\narccos_values = np.arccos(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arccos_values:<\/strong> [0. 1.04719755 1.57079633]<\/p>\n<h4>Trigonometric Inverse Tangent &#8211; numpy.arctan()<\/h4>\n<p>The numpy.arctan() function calculates the inverse tangent (in radians) for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 1, np.inf])\n\n# Compute inverse tangent\narctan_values = np.arctan(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arctan_values:<\/strong> [0. 0.78539816 1.57079633]<\/p>\n<h4>Element-wise Arc Tangent &#8211; numpy.arctan2()<\/h4>\n<p>The numpy.arctan2() function calculates the element-wise arc tangent of x1\/x2 while correctly choosing the quadrant.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input arrays\nx1 = np.array([1, -1, 1])\nx2 = np.array([1, 1, -1])\n\n# Compute element-wise arc tangent\narctan2_values = np.arctan2(x1, x2)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arctan2_values:<\/strong> [ 0.78539816 -0.78539816 2.35619449]<\/p>\n<h4>Convert Angles to Degrees &#8211; numpy.degrees()<\/h4>\n<p>The numpy.degrees() function converts angles from radians to degrees.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array in radians\narr_radians = np.array([0, np.pi\/2, np.pi])\n\n# Convert radians to degrees\narr_degrees = np.degrees(arr_radians)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arr_degrees:<\/strong> [ 0. 90. 180.]<\/p>\n<h4>Convert Angles to Radians &#8211; numpy.radians()<\/h4>\n<p>The numpy.radians() function converts angles from degrees to radians.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array in degrees\narr_degrees = np.array([0, 90, 180])\n\n# Convert degrees to radians\narr_radians = np.radians(arr_degrees)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arr_radians:<\/strong> [0. 1.57079633 3.14159265]<\/p>\n<h3>Hyperbolic Functions<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Function<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">sinh(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the hyperbolic sine (sinh) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">cosh(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the hyperbolic cosine (cosh) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">tanh(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the hyperbolic tangent (tanh) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">arcsinh(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the inverse hyperbolic sine (arcsinh) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">arccosh(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the inverse hyperbolic cosine (arccosh) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">arctanh(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the inverse hyperbolic tangent (arctanh) of each element in the input array, element-wise.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Compute Hyperbolic Tangent &#8211; numpy.tanh()<\/h4>\n<p>The numpy.tanh() function computes the hyperbolic tangent of each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 0.5, 1])\n\n# Compute hyperbolic tangent\ntanh_values = np.tanh(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>tanh_values:<\/strong> [0. 0.46211716 0.76159416]<\/p>\n<h4>Inverse Hyperbolic Sine &#8211; numpy.arcsinh()<\/h4>\n<p>The numpy.arcsinh() function calculates the inverse hyperbolic sine for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 1, 2])\n\n# Compute inverse hyperbolic sine\narcsinh_values = np.arcsinh(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arcsinh_values:<\/strong> [0. 0.88137359 1.44363548]<\/p>\n<h4>Inverse Hyperbolic Cosine &#8211; numpy.arccosh()<\/h4>\n<p>The numpy.arccosh() function calculates the inverse hyperbolic cosine for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1, 2, 3])\n\n# Compute inverse hyperbolic cosine\narccosh_values = np.arccosh(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arccosh_values:<\/strong> [0. 1.3169579 1.76274717]<\/p>\n<h4>Inverse Hyperbolic Tangent &#8211; numpy.arctanh()<\/h4>\n<p>The numpy.arctanh() function calculates the inverse hyperbolic tangent for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 0.5, 0.9])\n\n# Compute inverse hyperbolic tangent\narctanh_values = np.arctanh(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>arctanh_values:<\/strong> [0. 0.54930614 1.47221949]<\/p>\n<h3>Functions for Rounding<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Function<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">round(a[, decimals, out])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Round each element in the array &#8216;a&#8217; to the given number of &#8216;decimals&#8217; places.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">around(a[, decimals, out])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Round each element in the array &#8216;a&#8217; to the given number of &#8216;decimals&#8217; places, using &#8220;round half to even&#8221; rounding.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">rint(x, \/[, out, where, casting, order, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Round elements of the array &#8216;x&#8217; to the nearest integer.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">fix(x[, out])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Round each element in the array &#8216;x&#8217; to the nearest integer towards zero (truncate).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">floor(x, \/[, out, where, casting, order, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the floor (round down) of each element in the array &#8216;x&#8217;.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">ceil(x, \/[, out, where, casting, order, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the ceiling (round up) of each element in the array &#8216;x&#8217;.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">trunc(x, \/[, out, where, casting, order, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the truncated value of each element in the array &#8216;x&#8217;, removing the decimal part.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Round to Nearest Integer Towards Zero &#8211; numpy.rint()<\/h4>\n<p>The numpy.rint() function rounds the elements of the input array to the nearest integer towards zero.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1.1, 2.5, 3.9])\n\n# Round to nearest integer towards zero\nrint_values = np.rint(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>rint_values:<\/strong> [1. 2. 3.]<\/p>\n<h4>Round to Nearest Integer Towards Zero &#8211; numpy.fix()<\/h4>\n<p>The numpy.fix() function rounds the elements of the input array to the nearest integer towards zero.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1.1, 2.5, 3.9])\n\n# Round to nearest integer towards zero\nfix_values = np.fix(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>fix_values:<\/strong> [1. 2. 3.]<\/p>\n<h4>Return the Floor of the Input &#8211; numpy.floor()<\/h4>\n<p>The numpy.floor() function returns the largest integer not greater than the input array element-wise.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1.1, 2.5, 3.9])\n\n# Return floor of input\nfloor_values = np.floor(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>floor_values:<\/strong> [1. 2. 3.]<\/p>\n<h4>Return the Ceiling of the Input &#8211; numpy.ceil()<\/h4>\n<p>The numpy.ceil() function returns the smallest integer not less than the input array element-wise.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">  \nimport numpy as np\n\n# Input array\narr = np.array([1.1, 2.5, 3.9])\n\n# Return ceiling of input\nceil_values = np.ceil(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>ceil_values:<\/strong> [2. 3. 4.]<\/p>\n<h4>Return the Truncated Value &#8211; numpy.trunc()<\/h4>\n<p>The numpy.trunc() function returns the truncated value of the input array element-wise.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1.1, 2.5, 3.9])\n\n# Return truncated values\ntrunc_values = np.trunc(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>trunc_values:<\/strong> [1. 2. 3.]<\/p>\n<h3>Exponents and Logarithms Functions<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Function<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">exp(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the exponential (e^x) of each element in the input array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">expm1(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute e^x &#8211; 1 for each element in the input array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">exp2(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute 2^p for each p in the input array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">log(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the natural logarithm (base e) of each element in the input array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">log10(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the base 10 logarithm of each element in the input array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">log2(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the base 2 logarithm of each element in the input array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">log1p(x, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the natural logarithm of (1 + x) for each element in the input array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">logaddexp(x1, x2, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the logarithm of the sum of exponentials of &#8216;x1&#8217; and &#8216;x2&#8217;.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">logaddexp2(x1, x2, \/[, out, where, casting, &#8230;])<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compute the logarithm of the sum of exponentials in base-2 of &#8216;x1&#8217; and &#8216;x2&#8217;.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Calculate exp(x) &#8211; 1 &#8211; numpy.expm1()<\/h4>\n<p>The numpy.expm1() function calculates exp(x) &#8211; 1 for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 0.5, 1])\n\n# Calculate exp(x) - 1\nexpm1_values = np.expm1(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>expm1_values:<\/strong> [0. 0.64872127 1.71828183]<\/p>\n<h4>Calculate 2**p &#8211; numpy.exp2()<\/h4>\n<p>The numpy.exp2() function calculates 2**p for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 1, 2])\n\n# Calculate 2**p\nexp2_values = np.exp2(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>exp2_values:<\/strong> [1. 2. 4.]<\/p>\n<h4>Return the Base 10 Logarithm &#8211; numpy.log10()<\/h4>\n<p>The numpy.log10() function returns the base 10 logarithm of the input array element-wise.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1, 10, 100])\n\n# Return base 10 logarithm\nlog10_values = np.log10(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>log10_values:<\/strong> [0. 1. 2.]<\/p>\n<h4>Return the Base-2 Logarithm &#8211; numpy.log2()<\/h4>\n<p>The numpy.log2() function returns the base-2 logarithm of the input array element-wise.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([1, 2, 4])\n\n# Return base-2 logarithm\nlog2_values = np.log2(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>log2_values:<\/strong> [0. 1. 2.]<\/p>\n<h4>Returns the Natural Logarithm of One Plus the Input given &#8211; numpy.log1p()<\/h4>\n<p>The numpy.log1p() function returns the natural logarithm of 1 + x for each element in the input array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Input array\narr = np.array([0, 0.5, 1])\n\n# Return natural logarithm of 1 + x\nlog1p_values = np.log1p(arr)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>log1p_values:<\/strong> [0. 0.40546511 0.69314718]<\/p>\n<h4>Logarithm of the Sum of Exponentiations &#8211; numpy.logaddexp()<\/h4>\n<p>The numpy.logaddexp() function calculates the logarithm of the sum of exponentiations of the inputs.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\n\n# Inputs\nx = np.array([1, 2, 3])\ny = np.array([0.5, 1, 1.5])\n\n# Logarithm of the sum of exponentiations\nlogaddexp_values = np.logaddexp(x, y)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><span style=\"font-weight: 400\"><strong>logaddexp_values:<\/strong> [1.31326169 2.12692801 3.20951501]<\/span><\/p>\n<h4>The logarithm of the Sum of Exponentiations in Base-2 &#8211; numpy.logaddexp2()<\/h4>\n<p>The numpy.logaddexp2() function calculates the logarithm of the sum of exponentiations in base-2.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">  \nimport numpy as np\n\n# Inputs\nx = np.array([1, 2, 3])\ny = np.array([0.5, 1, 1.5])\n\n# Logarithm of the sum of exponentiations in base-2\nlogaddexp2_values = np.logaddexp2(x, y)<\/pre>\n<p><strong>Output<\/strong><br \/>\n<strong>logaddexp2_values:<\/strong> [1.5849625 2.32192809 3.169925 ]<\/p>\n<p>Whether you&#8217;re a data scientist exploring trends in a massive dataset, an engineer simulating physical systems, or a researcher solving mathematical problems, NumPy&#8217;s functions have your back.<\/p>\n<h3>Conclusion<\/h3>\n<p>In this blog, we&#8217;ve only scratched the surface of the myriad mathematical functions NumPy has to offer. To fully harness their power, one must continue exploring, experimenting, and applying them to real-world challenges.<\/p>\n<p>As you continue your journey in the world of Python programming and data analysis, remember that NumPy&#8217;s mathematical functions are your trusty companions, ready to assist you in unravelling the mysteries of the mathematical universe and turning data into knowledge.<\/p>\n<p>Remember to visit TechVidvan for more insightful tutorials and resources on data manipulation, analysis, and more. Happy coding with Numpy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will explore a variety of mathematical functions that Numpy offers, along with examples demonstrating their usage. Let&#8217;s dive in and see how these functions can enhance your data manipulation and&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":88971,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[385],"tags":[5283,5284,5247,5285,5286],"class_list":["post-88793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy-tutorials","tag-mathematical-functions","tag-mathematical-functions-in-numpy","tag-numpy","tag-numpy-mathematical-functions","tag-numpy-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>NumPy Mathematical Functions - TechVidvan<\/title>\n<meta name=\"description\" content=\"In this tutorial, we will explore a variety of mathematical functions that Numpy offers, along with examples demonstrating their usage.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NumPy Mathematical Functions - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we will explore a variety of mathematical functions that Numpy offers, along with examples demonstrating their usage.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-04T12:30:28+00:00\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"NumPy Mathematical Functions - TechVidvan","description":"In this tutorial, we will explore a variety of mathematical functions that Numpy offers, along with examples demonstrating their usage.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/","og_locale":"en_US","og_type":"article","og_title":"NumPy Mathematical Functions - TechVidvan","og_description":"In this tutorial, we will explore a variety of mathematical functions that Numpy offers, along with examples demonstrating their usage.","og_url":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2023-12-04T12:30:28+00:00","author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"NumPy Mathematical Functions","datePublished":"2023-12-04T12:30:28+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/"},"wordCount":1374,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#primaryimage"},"thumbnailUrl":"","keywords":["mathematical functions","mathematical functions in numpy","numpy","numpy mathematical functions","numpy tutorials"],"articleSection":["NumPy Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/","url":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/","name":"NumPy Mathematical Functions - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#primaryimage"},"thumbnailUrl":"","datePublished":"2023-12-04T12:30:28+00:00","description":"In this tutorial, we will explore a variety of mathematical functions that Numpy offers, along with examples demonstrating their usage.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-mathematical-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"NumPy Mathematical Functions"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/88793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=88793"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/88793\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=88793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=88793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=88793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}