- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return the cube-root of an array elementwise in Numpy
To return the cube-root of an array, element-wise, use the numpy.cbrt() method in Python Numpy. An array of the same shape as x, containing the cube cube-root of each element in x. If out was provided, y is a reference to it. This is a scalar if x is a scalar.
The condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more. It supports a wide range of hardware and computing platforms, and plays well with distributed, GPU, and sparse array libraries.
Steps
At first, import the required library −
import numpy as np
Create an array using the array() method −
arr = np.array([125, 27, 1000, 100, 841, 225])
Display the array −
print("Array...
", arr)
Get the type of the array −
print("
Our Array type...
", arr.dtype)
Get the dimensions of the Array −
print("
Our Array Dimension...
",arr.ndim)
Get the shape of the Array −
print("
Our Array Shape...
",arr.shape)
To return the cube-root of an array, element-wise, use the numpy.cbrt() method in Python Numpy −
print("
Result...
",np.cbrt(arr))
Example
import numpy as np # Create an array using the array() method arr = np.array([125, 27, 1000, 100, 841, 225]) # Display the array print("Array...
", arr) # Get the type of the array print("
Our Array type...
", arr.dtype) # Get the dimensions of the Array print("
Our Array Dimension...
",arr.ndim) # Get the shape of the Array print("
Our Array Shape...
",arr.shape) # To return the cube-root of an array, element-wise, use the numpy.cbrt() method in Python Numpy print("
Result...
",np.cbrt(arr))
Output
Array... [ 125 27 1000 100 841 225] Our Array type... int64 Our Array Dimension... 1 Our Array Shape... (6,) Result... [ 5. 3. 10. 4.64158883 9.43913068 6.082202 ]
- Related Articles
- Return the non-negative square-root of an array element-wise in Numpy
- Return the element-wise square-root of a complex type array in Numpy
- Return the Lower triangle of an array in Numpy
- Return the Upper triangle of an array in Numpy
- Return the identity array in Numpy
- Cube each element in a Numpy array
- Return the transpose of the masked array in NumPy
- Return the floor of the array elements in Numpy
- Return the length of the masked array in Numpy
- Return an array with the elements of an array left-justified in a string of length width in Numpy
- Return a copy of the masked array in NumPy
- Return the mask of a masked array in Numpy
- Return an array formed from the elements of a masked array at the given indices in NumPy
- Return an array formed from the elements of a masked array but clip the range in NumPy
- Return the average of the masked array elements in Numpy
