在 NumPy 中使用复杂输入返回几何级数上均匀间隔的数字
要返回几何级数上均匀间隔的数字,请在 Python NumPy 中使用 **numpy.geomspace()** 方法 -
- 第一个参数是“start”,即序列的开始
- 第二个参数是“end”,即序列的结束
- 第三个参数是 num,即要生成的样本数。默认为 50。
我们设置了复杂输入。
start 是序列的起始值。stop 是序列的最终值,除非 endpoint 为 False。在这种情况下,num + 1 个值在对数空间中间隔开,其中除了最后一个(长度为 num 的序列)之外的所有值都将被返回。如果 endpoint 为 True,则 stop 是最后一个样本。否则,它不包括在内。默认为 True。
结果中存储样本的轴。仅当 start 或 stop 为数组状时才相关。默认情况下 (0),样本将沿着插入到开头的新的轴。使用 -1 在末尾获取轴。
步骤
首先,导入所需的库 -
import numpy as np
返回几何级数上均匀间隔的数字,使用 numpy.geomspace() 方法 -
arr = np.geomspace(10j, 100j, num = 5)
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 geometric progression, use the numpy.geomspace() 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.s the number of samples to generate. Default is 50.
# We have set complex inputs
arr = np.geomspace(10j, 100j, num = 5)
print("Array...
", arr)
# Get the type
print("
Type...
", arr.dtype)
# Get the dimensions
print("
Dimensions...
",arr.ndim)
# Get the shape
print("
Shape...
",arr.shape)
# Get the number of elements
print("
Number of elements...
",arr.size)输出
Array... [0. +10.j 0. +17.7827941j 0. +31.6227766j 0. +56.23413252j 0.+100.j ] Type... complex128 Dimensions... 1 Shape... (5,) Number of elements... 5
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP