YDOOK:Python numpy np.logspace 定义 等比数组 详细教程

tech2023-02-28  95

Python numpy np.logspace 定义 等比数组

logspace 的参数:

start 序列的起始值为:base ** start stop 序列的终止值为:base ** stop。 num 要生成的等步长的样本数量,默认为50。 endpoint 该值为 true 时,数列中中包含stop值,反之不包含,默认是True。 base 对数 log 的底数,用于设置等比数列的底数。 dtype ndarray 的数据类型

示例:

import numpy as np # The default base number is 10 a = np.logspace(1.0, 2.0, 2) print('1 a = ', a) a = np.logspace(1.0, 2.0, num=2) print('2 a = ', a) a = np.logspace(1.0, 2.0, 2, base=2) print('3 a = ', a) a = np.logspace(1.0, 2.0, 2, True) print('4 a = ', a) a = np.logspace(1.0, 2.0, 2, False) print('5 a = ', a) a = np.logspace(1.0, 2.0, 2, True, 1) print('6 a = ', a) a = np.logspace(1.0, 2.0, 2, True, 2) print('7 a = ', a) a = np.logspace(1.0, 2.0, 2, True, 10) print('8 a = ', a) a = np.logspace(1.0, 2.0, 2, True, 10, int) print('9 a = ', a) a = np.logspace(1.0, 2.0, 2, True, 10, float) print('10 a = ', a) a = np.logspace(1.0, 2.0, 2, True, 10, bool) print('11 a = ', a) a = np.logspace(1.0, 2.0, 2, True, 10, str) print('12 a = ', a)

结果

1 a = [ 10. 100.] 2 a = [ 10. 100.] 3 a = [2. 4.] 4 a = [ 10. 100.] 5 a = [10. 31.6227766] 6 a = [1. 1.] 7 a = [2. 4.] 8 a = [ 10. 100.] 9 a = [ 10 100] 10 a = [ 10. 100.] 11 a = [ True True] 12 a = ['10.0' '100.0'] Process finished with exit code 0
最新回复(0)