I have this sparse vector val
with this Pythonic ways:
idx = [2, 5, 6]
val = [69, 12, 15]
_ = np.zeros(idx[-1])
# This is not numpythonic because still using `for` syntax.
for i in range(len(idx)):
_[idx[i]-1 : idx[i]+1] = val[i]
Here is the output:
[ 0. 69. 69. 0. 12. 15.]
(6,)
float64
How do I achieve my goals where it’s not using for loops, instead using numpythonic way?