python
runtime_error
ai_generated
true
ValueError: assignment destination is read-only
ID: python/numpy-array-not-writeable
80%Fix Rate
88%Confidence
0Evidence
2025-01-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Array is read-only (e.g., from np.broadcast_to or a view backed by immutable buffer).
generic中文
数组为只读(例如来自 np.broadcast_to 或不可变缓冲区视图)。
Workarounds
-
95% success
arr = np.array(arr, copy=True) before mutation
-
85% success
arr.setflags(write=True) when array is a writable view
Dead Ends
Common approaches that don't work:
-
85% fail
Still read-only; same error
-
60% fail
May raise if buffer is genuinely immutable