jax.numpy.empty_like#
- jax.numpy.empty_like(prototype, dtype=None, shape=None, *, device=None)[source]#
Create an empty array with the same shape and dtype as an array.
JAX implementation of
numpy.empty_like(). Starting in JAX v0.11.0, this returns an uninitialized array on platforms that support doing so. Prior to v0.11.0, this function returned an array filled with zeros on all platforms.- Parameters:
prototype (Array | ndarray | bool | number | bool | int | float | complex | DuckTypedArray) – Array-like object with
shapeanddtypeattributes.dtype (str | type[Any] | dtype | SupportsDType | None) – optionally override the dtype of the created array.
shape (Any) – optionally override the shape of the created array.
device (Device | Sharding | None) – (optional)
DeviceorShardingto which the created array will be committed.
- Returns:
Array of the specified shape and dtype, on the specified device if specified.
- Return type:
Examples
>>> x = jnp.arange(4) >>> jnp.empty_like(x) Array([0, 0, 0, 0], dtype=int32) >>> jnp.empty_like(x, dtype=bool) Array([False, False, False, False], dtype=bool) >>> jnp.empty_like(x, shape=(2, 3)) Array([[0, 0, 0], [0, 0, 0]], dtype=int32)