jax.numpy.zeros_like — JAX documentation (original) (raw)
jax.numpy.zeros_like#
jax.numpy.zeros_like(a, dtype=None, shape=None, *, device=None, out_sharding=None)[source]#
Create an array full of zeros with the same shape and dtype as an array.
JAX implementation of numpy.zeros_like().
Parameters:
- a (Array | ndarray | bool | number | bool | int | float | complex | TypedNdArray | DuckTypedArray) – Array-like object with
shapeanddtypeattributes. - shape (Any) – optionally override the shape of the created array.
- dtype (str | type_[_Any] | dtype | SupportsDType | None) – optionally override the dtype of the created array.
- device (Device | Sharding | None) – (optional) Device or Shardingto which the created array will be committed.
- out_sharding (NamedSharding | PartitionSpec | None)
Returns:
Array of the specified shape and dtype, on the specified device if specified.
Return type:
See also
Examples
x = jnp.arange(4) jnp.zeros_like(x) Array([0, 0, 0, 0], dtype=int32) jnp.zeros_like(x, dtype=bool) Array([False, False, False, False], dtype=bool) jnp.zeros_like(x, shape=(2, 3)) Array([[0, 0, 0], [0, 0, 0]], dtype=int32)