在NumPy中逐元素返回输入数组的以10为底的对数
要逐元素返回输入数组的以10为底的对数,请在Python NumPy中使用**numpy.log10()**方法。对于实值输入数据类型,log10始终返回实数输出。对于无法表示为实数或无穷大的每个值,它会产生nan并设置无效浮点错误标志。
逐元素返回x的以10为底的对数。当x为负数时,返回NaN。如果x是标量,则这是一个标量。
out是存储结果的位置。如果提供,它必须具有输入广播到的形状。如果不提供或为None,则返回一个新分配的数组。元组(只能作为关键字参数)的长度必须等于输出的数量。
步骤
首先,导入所需的库:
import numpy as np
使用array()方法创建一个数组:
arr = np.array([1e-15, 10000])
显示数组:
print("Array...
", arr)获取数组的类型:
print("
Our Array type...
", arr.dtype)
获取数组的维数:
print("
Our Array Dimension...
",arr.ndim)获取数组的形状:
print("
Our Array Shape...
",arr.shape)
要逐元素返回输入数组的以10为底的对数,请使用numpy.log10()方法。对于实值输入数据类型,log10始终返回实数输出。对于无法表示为实数或无穷大的每个值,它会产生nan并设置无效浮点错误标志:
print("
Result...
",np.log10(arr))示例
import numpy as np
# Create an array using the array() method
arr = np.array([1e-15, 10000])
# 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 base 10 logarithm of the input array, element-wise, use the numpy.logaddexp() method in Python Numpy
# For real-valued input data types, log10 always returns real output.
# For each value that cannot be expressed as a real number or infinity,
# it yields nan and sets the invalid floating point error flag.
print("
Result...
",np.log10(arr))输出
Array... [1.e-15 1.e+04] Our Array type... float64 Our Array Dimension... 1 Our Array Shape... (2,) Result... [-15. 4.]
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP