jax.numpy.logspace#
- jax.numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0)[source]#
生成对数刻度的值。
numpy.logspace()
的 JAX 实现。- 参数:
start (ArrayLike) – 标量或数组。用于指定起始值。起始值是
base ** start
。stop (ArrayLike) – 标量或数组。用于指定停止值。结束值是
base ** stop
。num (int) – int,可选,默认值=50。要生成的值的数量。
endpoint (bool) – bool,可选,默认值=True。如果为 True,则在结果中包含
stop
值。如果为 False,则排除stop
值。base (ArrayLike) – 标量或数组,可选,默认值=10。指定对数的基数。
dtype (DTypeLike | None | None) – 可选。指定输出的 dtype。
axis (int) – int,可选,默认值=0。沿其生成 logspace 的轴。
- 返回:
对数数组。
- 返回类型:
参见
jax.numpy.arange()
: 生成给定起点和步长值的N
个均匀间隔的值。jax.numpy.linspace()
: 生成均匀间隔的值。jax.numpy.geomspace()
: 生成几何间隔的值。
示例
列出 1 (
10 ** 0
) 和 100 (10 ** 2
) 之间 5 个对数间隔的值>>> with jnp.printoptions(precision=3, suppress=True): ... jnp.logspace(0, 2, 5) Array([ 1. , 3.162, 10. , 31.623, 100. ], dtype=float32)
列出 1(
10 ** 0
) 和 100 (10 ** 2
) 之间 5 个对数间隔的值,排除端点>>> with jnp.printoptions(precision=3, suppress=True): ... jnp.logspace(0, 2, 5, endpoint=False) Array([ 1. , 2.512, 6.31 , 15.849, 39.811], dtype=float32)
列出 1 (
2 ** 0
) 和 4 (2 ** 2
) 之间以 2 为基数的 7 个对数间隔的值>>> with jnp.printoptions(precision=3, suppress=True): ... jnp.logspace(0, 2, 7, base=2) Array([1. , 1.26 , 1.587, 2. , 2.52 , 3.175, 4. ], dtype=float32)
多维 logspace
>>> start = jnp.array([0, 5]) >>> stop = jnp.array([5, 0]) >>> base = jnp.array([2, 3]) >>> with jnp.printoptions(precision=3, suppress=True): ... jnp.logspace(start, stop, 5, base=base) Array([[ 1. , 243. ], [ 2.378, 61.547], [ 5.657, 15.588], [ 13.454, 3.948], [ 32. , 1. ]], dtype=float32)