Skip to content

Conversation

@clijo
Copy link

@clijo clijo commented Jan 10, 2026

The original example in Exercise 1 of 01 - JAX AI Stack.ipynb assigned the result to a new variable (a_sol_new_ref), leaving the original variable (a_sol) and its binding strictly unchanged:

a_sol_new_ref = a_sol + 1 # This creates a new array and rebinds the Python variable.

This fails to demonstrate anything about the mutability of the original object.

Fix: I have changed this to:

a_sol += 1 # This creates a new array and rebinds the variable `a_sol`.
# a_sol = a_sol + 1  # same as above line, an out-of-place update.
new_a_id_sol = id(a_sol)

Because += would be the syntax for in-place update for NumPy arrays. I have also added a code block demonstrating how the id would be unchanged in NumPy with an in-place update:

import numpy as np 
a = np.random.random((2,2))
original_id = id(a)
a += 1 
new_id = id(a)
print(f"(NumPy, in-place update) IDs are different? {original_id != new_id}")

# One can also do an out-of-place update:
a = a + 1
new_id_out = id(a)
print(f"(NumPy, out-of-place update) IDs are different? {original_id != new_id_out}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant