keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.06k stars 19.35k forks source link

ops.copy makes object (arrays only?) immutable #19665

Closed Mrutyunjay01 closed 2 weeks ago

Mrutyunjay01 commented 2 weeks ago

Issue:

When trying to overwrite an object after making a copy using ops.copy, it makes the object immutable. Even after explicitly converting to numpy using ops.convert_to_numpy, the copied object remains immutable.

How to Reproduce:

import numpy as np
from keras import ops

arr = np.arange(10)
ops_arr = ops.copy(arr)

print(type(ops_arr)) # now it's EagerTensor

ops_arr_np = ops.convert_to_numpy(ops_arr)
print(ops_arr_np) # of type ndarray

ops_arr_np[0] = 10

And the error that follows:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
# in <cell line: 9>()
      7 print(ops_arr_np) # of type ndarray
      8 
----> 9 ops_arr_np[0] = 10

ValueError: assignment destination is read-only
fchollet commented 2 weeks ago

Thanks for the report, this is now fixed at HEAD.