jax.lax.squeeze#
- jax.lax.squeeze(array, dimensions)[source]#
Squeeze any number of size 1 dimensions from an array.
- Parameters:
array (ArrayLike) – input array
dimensions (Sequence[int]) – sequence of integers specifying axes to remove. If any specified axis does not have a size of 1, an error is raised.
- Returns:
Array with the specified size-1 dimensions removed.
- Return type:
See also
jax.lax.expand_dims(): the inverse ofsqueeze: add dimensions of size 1.jax.numpy.squeeze(): equivalent numpy API.
Examples
>>> x = jnp.array([[[0]], [[1]], [[2]]]) >>> x.shape (3, 1, 1)
Squeeze the specified size-1 dimensions:
>>> jax.lax.squeeze(x, dimensions=(1, 2)) Array([0, 1, 2], dtype=int32) >>> _.shape (3,)
Attempting to squeeze a non-unit axis results in an error:
>>> jax.lax.squeeze(x, dimensions=(0,)) Traceback (most recent call last): ... ValueError: cannot select an axis to squeeze out which has size not equal to one, got shape=(3, 1, 1) and dimensions=(0,)