在 Numpy 中返回对数刻度上的等间距数字,并且不设置端点
要返回对数刻度上的等间距数字,请在 Python Numpy 中使用 numpy.logspace() 方法。第一个参数是“start”,即序列的开始。第二个参数是“end”,即序列的结束。第三个参数是“num”,即要生成的样本数。默认为 50。第四个参数是“endpoint”。如果为 True,则 stop 是最后一个样本。否则,它不包含在内。默认为 True。
在线性空间中,序列从 base ** start(底数的 start 次幂)开始,以 base ** stop(参见下面的 endpoint)结束。start 是 base ** start 是序列的起始值。stop 是 base ** stop 是序列的最终值,除非 endpoint 为 False。在这种情况下,num + 1 个值在对数空间中的区间内等距分布,其中除了最后一个值之外的所有值都将被返回。对数空间的底数。ln(samples) / ln(base)(或 log_base(samples))中的元素之间的步长是统一的。默认为 10.0。
结果中存储样本的轴。仅当 start 或 stop 为数组状时才相关。默认情况下(0),样本将沿着插入到开头的新轴。使用 -1 获取末尾的轴。
步骤
首先,导入所需的库 -
import numpy as np
要返回对数刻度上的等间距数字,请使用 numpy.logspace() 方法 -
arr = np.logspace(100.5, 200.7, num = 10, endpoint = False)
print("Array...
", arr)获取数组类型 -
print("
Type...
", arr.dtype)获取数组的维度 -
print("
Dimensions...
",arr.ndim)获取数组的形状 -
print("
Shape...
",arr.shape)
获取元素的数量 -
print("
Number of elements...
",arr.size)示例
import numpy as np
# To return evenly spaced numbers on a log scale, use the numpy.logspace() method in Python Numpy
# The 1st parameter is the "start" i.e. the start of the sequence
# The 2nd parameter is the "end" i.e. the end of the sequence
# The 3rd parameter is the "num" i.e the number of samples to generate. Default is 50.
# The 4th parameter is the "endpoint". If True, stop is the last sample. Otherwise, it is not included. Default is True.
arr = np.logspace(100.5, 200.7, num = 10, endpoint = False)
print("Array...
", arr)
# Get the array type
print("
Type...
", arr.dtype)
# Get the dimensions of the Array
print("
Dimensions...
",arr.ndim)
# Get the shape of the Array
print("
Shape...
",arr.shape)
# Get the number of elements
print("
Number of elements...
",arr.size)输出
Array... [3.16227766e+100 3.31131121e+110 3.46736850e+120 3.63078055e+130 3.80189396e+140 3.98107171e+150 4.16869383e+160 4.36515832e+170 4.57088190e+180 4.78630092e+190] Type... float64 Dimensions... 1 Shape... (10,) Number of elements... 10
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP