MCPcopy
hub / github.com/jax-ml/jax / append

Function append

jax/_src/numpy/lax_numpy.py:7524–7574  ·  view source on GitHub ↗

Return a new array with values appended to the end of the original array. JAX implementation of :func:`numpy.append`. Args: arr: original array. values: values to be appended to the array. The ``values`` must have the same number of dimensions as ``arr``, and all dimensions must

(
    arr: ArrayLike, values: ArrayLike, axis: int | None = None
)

Source from the content-addressed store, hash-verified

7522@export
7523@api.jit(static_argnames=('axis',))
7524def append(
7525 arr: ArrayLike, values: ArrayLike, axis: int | None = None
7526) -> Array:
7527 """Return a new array with values appended to the end of the original array.
7528
7529 JAX implementation of :func:`numpy.append`.
7530
7531 Args:
7532 arr: original array.
7533 values: values to be appended to the array. The ``values`` must have
7534 the same number of dimensions as ``arr``, and all dimensions must
7535 match except in the specified axis.
7536 axis: axis along which to append values. If None (default), both ``arr``
7537 and ``values`` will be flattened before appending.
7538
7539 Returns:
7540 A new array with values appended to ``arr``.
7541
7542 See also:
7543 - :func:`jax.numpy.insert`
7544 - :func:`jax.numpy.delete`
7545
7546 Examples:
7547 >>> a = jnp.array([1, 2, 3])
7548 >>> b = jnp.array([4, 5, 6])
7549 >>> jnp.append(a, b)
7550 Array([1, 2, 3, 4, 5, 6], dtype=int32)
7551
7552 Appending along a specific axis:
7553
7554 >>> a = jnp.array([[1, 2],
7555 ... [3, 4]])
7556 >>> b = jnp.array([[5, 6]])
7557 >>> jnp.append(a, b, axis=0)
7558 Array([[1, 2],
7559 [3, 4],
7560 [5, 6]], dtype=int32)
7561
7562 Appending along a trailing axis:
7563
7564 >>> a = jnp.array([[1, 2, 3],
7565 ... [4, 5, 6]])
7566 >>> b = jnp.array([[7], [8]])
7567 >>> jnp.append(a, b, axis=1)
7568 Array([[1, 2, 3, 7],
7569 [4, 5, 6, 8]], dtype=int32)
7570 """
7571 if axis is None:
7572 return concatenate([ravel(arr), ravel(values)], 0)
7573 else:
7574 return concatenate([arr, values], axis=axis)
7575
7576
7577@export

Callers 1

_uniqueFunction · 0.90

Calls 2

ravelFunction · 0.85
concatenateFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…