

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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...\n", arr)
Get the type of the array −
print("\nOur Array type...\n", arr.dtype)
Get the dimensions of the Array −
print("\nOur Array Dimension...\n",arr.ndim)
Get the shape of the Array −
print("\nOur Array Shape...\n",arr.shape)
To return the cube-root of an array, element-wise, use the numpy.cbrt() method in Python Numpy −
print("\nResult...\n",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...\n", arr) # Get the type of the array print("\nOur Array type...\n", arr.dtype) # Get the dimensions of the Array print("\nOur Array Dimension...\n",arr.ndim) # Get the shape of the Array print("\nOur Array Shape...\n",arr.shape) # To return the cube-root of an array, element-wise, use the numpy.cbrt() method in Python Numpy print("\nResult...\n",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 Questions & Answers
- 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
- Cube each element in a Numpy array
- Return the identity array in Numpy
- How to find the cube root of a number in JavaScript?
- How to find the cube root of negative values in R?
- 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
- Java program to find the cube root of a given number
- Return a copy of the masked array in NumPy
- Return the mask of a masked array in Numpy
- Return the average of the masked array elements in Numpy