From c5d2937aa5d272145fe6f36a0d577ae3c84f12c7 Mon Sep 17 00:00:00 2001 From: Krishi Saripalli <73147583+krishi-saripalli@users.noreply.github.com> Date: Tue, 2 Sep 2025 22:07:02 -0700 Subject: [PATCH] chore: Update Docs With Slice Copy Example (#2559) * chore: updated docs with slice copy example * nits --------- Co-authored-by: Awni Hannun --- docs/src/usage/indexing.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/src/usage/indexing.rst b/docs/src/usage/indexing.rst index dcbc84c1b..f454a3d55 100644 --- a/docs/src/usage/indexing.rst +++ b/docs/src/usage/indexing.rst @@ -107,8 +107,20 @@ same array: >>> a array([1, 2, 0], dtype=int32) +Note that unlike NumPy, slicing an array creates a copy, not a view. So +mutating it does not mutate the original array: -Note, unlike NumPy, updates to the same location are nondeterministic: +.. code-block:: shell + + >>> a = mx.array([1, 2, 3]) + >>> b = a[:] + >>> b[2] = 0 + >>> b + array([1, 2, 0], dtype=int32) + >>> a + array([1, 2, 3], dtype=int32) + +Also unlike NumPy, updates to the same location are nondeterministic: .. code-block:: shell