jax.numpy.full_like#
- jax.numpy.full_like(a, fill_value, dtype=None, shape=None, *, device=None)[源代码]#
创建一个与给定数组具有相同形状和数据类型的、填充了指定值的数组。
JAX 对
numpy.full_like()
的实现。- 参数:
a (Array | ndarray | bool | number | bool | int | float | complex | DuckTypedArray) – 具有
shape
和dtype
属性的类数组对象。fill_value (Array | ndarray | bool | number | bool | int | float | complex) – 用于填充所创建数组的标量或数组。
shape (Any) – 可选地覆盖创建数组的形状。
dtype (str | type[Any] | dtype | SupportsDType | None) – 可选地覆盖所创建数组的数据类型。
device (Device | Sharding | None) – (可选) 创建的数组将提交到的
Device
或Sharding
。
- 返回:
具有指定形状和数据类型,并在指定设备(如果已指定)上的数组。
- 返回类型:
示例
>>> x = jnp.arange(4.0) >>> jnp.full_like(x, 2) Array([2., 2., 2., 2.], dtype=float32) >>> jnp.full_like(x, 0, shape=(2, 3)) Array([[0., 0., 0.], [0., 0., 0.]], dtype=float32)
fill_value 也可以是一个会被广播到指定形状的数组
>>> x = jnp.arange(6).reshape(2, 3) >>> jnp.full_like(x, fill_value=jnp.array([[1], [2]])) Array([[1, 1, 1], [2, 2, 2]], dtype=int32)