arr = np.zeros([5,5])
idx_arr = np.array([1,3,4])
arr[idx_arr, idx_arr] += 1
print(arr)
Above gives the following output:
array([[0., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
I'm looking for the following output:
array([[0., 0., 0., 0., 0.],
[0., 1., 0., 1., 1.],
[0., 0., 0., 0., 0.],
[0., 1., 0., 1., 1.],
[0., 1., 0., 1., 1.]])
In R, this form of indexing would be equivalent to:
df[c(1,2,3),c(1,2,3)]
Which would produce a 3 x 3 data frame or matrix sub-section.
Any help would be greatly appreciated!