NumPy中数组的逐元素立方根
要在Python NumPy中逐元素返回数组的立方根,请使用**numpy.cbrt()**方法。返回一个与x形状相同的数组,其中包含x中每个元素的立方根。如果提供了out,则y是对它的引用。如果x是标量,则这是一个标量。
此条件会广播到输入。在条件为True的位置,out数组将设置为ufunc结果。在其他位置,out数组将保留其原始值。请注意,如果通过默认的out=None创建未初始化的out数组,则其中条件为False的位置将保持未初始化状态。
NumPy 提供了全面的数学函数、随机数生成器、线性代数例程、傅里叶变换等等。它支持各种硬件和计算平台,并且可以很好地与分布式、GPU和稀疏数组库配合使用。
步骤
首先,导入所需的库:
import numpy as np
使用array()方法创建一个数组:
arr = np.array([125, 27, 1000, 100, 841, 225])
显示数组:
print("Array...
", arr)获取数组的类型:
print("
Our Array type...
", arr.dtype)
获取数组的维度:
print("
Our Array Dimension...
",arr.ndim)获取数组的形状:
print("
Our Array Shape...
",arr.shape)
要在Python NumPy中逐元素返回数组的立方根,请使用numpy.cbrt()方法:
print("
Result...
",np.cbrt(arr))示例
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))输出
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 ]
广告
数据结构
网络
关系数据库管理系统(RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP