Wondering if there is an easy way to do this:
Say I have an numpy array with the shape (2,3,2), for example:
x =
[[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10,11]]]
If I wanted to replace all the entries that corresponded to axis=1 and position=0, with zero, I could do this easily:
x[:,0,:] = 0
x =
[[[ 0 0]
[ 2 3]
[ 4 5]]
[[ 0 0]
[ 8 9]
[10 11]]]
However, what If I had a list of axes that I wanted to perform these operations on. Is there a built-in numpy function for this? Ideally it'd look something like this:
array_replace(array=x,axis=1,pos=0,replace_val=0)
Which would give the same array as above.
I can think of a way to do this by flattening matrices and calculating where the positions of each variable would be based on the dimension of each array, but I'm wondering if there is already something built into numpy.