jax.numpy.logspace#
- jax.numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0)[源码]#
生成对数间隔的值。
JAX 对
numpy.logspace()的实现。- 参数:
start (Array | ndarray | bool | number | bool | int | float | complex | TypedNdArray) – 标量或数组。用于指定起始值。起始值为
base ** start。stop (Array | ndarray | bool | number | bool | int | float | complex | TypedNdArray) – 标量或数组。用于指定结束值。结束值为
base ** stop。num (int) – 整数,可选,默认为 50。要生成的数值个数。
endpoint (bool) – 布尔值,可选,默认为 True。如果为 True,则在结果中包含
stop值。如果为 False,则排除stop值。base (Array | ndarray | bool | number | bool | int | float | complex | TypedNdArray) – 标量或数组,可选,默认为 10.0。指定对数的底。
dtype (str | type[Any] | dtype | SupportsDType | None) – 可选。指定输出的数据类型。
axis (int) – 整数,可选,默认为 0。生成对数空间的轴。
- 返回:
对数数组。
- 返回类型:
另请参阅
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)
多维对数空间
>>> 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)