How can SciPy be used to calculate the cube root of values and exponential values in Python?

SciPy provides powerful mathematical functions through its special module. Two commonly used functions are cbrt() for calculating cube roots and exp10() for computing 10 raised to the power of x.

Calculating Cube Root with cbrt()

The cbrt() function computes the cube root of given values.

Syntax

scipy.special.cbrt(x)

Where x is the input value or array for which you want to calculate the cube root.

Example

from scipy.special import cbrt

# Calculate cube root of individual values
values = [27, 64, 125, 89]
cube_roots = cbrt(values)

print("Original values:", values)
print("Cube roots:", cube_roots)

# Verification
print("Verification: 3³ =", 3**3)
print("Verification: 4³ =", 4**3)
Original values: [27, 64, 125, 89]
Cube roots: [3.         4.         5.         4.4647451 ]
Verification: 3³ = 27
Verification: 4³ = 64

Calculating 10^x with exp10()

The exp10() function computes 10 raised to the power of x (10^x).

Syntax

scipy.special.exp10(x)

Where x is the exponent value or array.

Example

from scipy.special import exp10

# Calculate 10^x for different values
exponents = [2, 3, 5, 12]
exponential_values = exp10(exponents)

print("Exponents:", exponents)
print("10^x values:", exponential_values)

# Single value example
single_exp = exp10(4)
print("10^4 =", single_exp)
Exponents: [2, 3, 5, 12]
10^x values: [1.e+02 1.e+03 1.e+05 1.e+12]
10^4 = 10000.0

Working with Arrays and Different Data Types

Both functions work seamlessly with NumPy arrays and different numeric data types ?

import numpy as np
from scipy.special import cbrt, exp10

# Using with NumPy arrays
arr = np.array([8, 27, 64, 216])
cube_roots = cbrt(arr)

print("Array cube roots:", cube_roots)

# Using with floating point numbers
float_values = [1.5, 2.5, 3.7]
exp_values = exp10(float_values)

print("10^x for floats:", exp_values)
Array cube roots: [2. 3. 4. 6.]
10^x for floats: [ 31.6227766  316.22776602 5011.87233627]

Comparison

Function Purpose Input Range Example
cbrt(x) Cube root (x^(1/3)) Any real number cbrt(27) = 3
exp10(x) 10 to the power x Any real number exp10(2) = 100

Conclusion

SciPy's special.cbrt() efficiently calculates cube roots while special.exp10() computes powers of 10. Both functions handle arrays and provide accurate mathematical computations for scientific applications.

Updated on: 2026-03-25T13:17:15+05:30

674 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements