numpy arrays can be partially assigned using integer or boolean indices like this:
import numpy as np
x = np.arange(5)
x[[2,4]]=0
x
## array([0., 0., 1., 0., 1.])
x[[True]*2+[False]*3]=2
x
## array([2., 2., 1., 0., 1.])
However, even though x[[2,4]] is in lvalue in this context, the lvalue cannot be assigned to another variable, because in this case the assignment is done by __setitem__, whereas __getitem__, when passed an integer or boolean list, creates a copy:
x = np.arange(5)
y = x[[2,4]]
y[:] = 1
x
array([0., 0., 0., 0., 0.])
Question: is there any simple/clean way to get a writeable array view based on an integer-indexed or boolean-indexed index subset? By "simple/clean" I mean that I want to avoid writing a new class, or keeping track of the sub-indices myself. Basically I'm looking for some numpy function or trick that I haven't been able to google.
The point of this question is to be able to do this recursively, to be able to create functions that assign to pieces of an array by just passing views of the array around, rather than passing indices as well as the base array.
viewmodel can handle.