What is the numpy.cbrt() function in NumPy?
Overview
The cbrt() function in NumPy computes the cube root of each element in an input array.
Syntax
numpy.cbrt(x, /, out=None, *, where=True)
Syntax for the cbrt() function
Parameters
The cbrt() function takes the following parameter values:
x: This represents the input array of values. This is a required parameter.out: This represents the location where the result is stored. This is an optional parameter.where: This is the condition over which the input is being broadcast. At a given location where this condition isTrue, the resulting array will be set to theufuncresult. Otherwise, the resulting array retains its original value.**kwargs: This represents other keyword arguments. This is an optional parameter.
Return value
The cbrt() function returns an array of the same shape as the input array passed to it. This array holds the cube root values of the input array's elements.
Example
import numpy as np# creating an input array of complex valuesx = np.array([1, 8, 27, 64, 125])# implementing the cbrt() functionmyarray = np.cbrt(x)print(x)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create an array,
x, using thearray()function. - Line 7: We implement the
cbrt()function on the input array. We assign the result to a variable,myarray. - Line 9: We print the variable,
x. - Line 10: We print the
myarrayvariable.