Skip to content
Advertisement

Numpy array assignment along axis and index

I have a 3D volume and I modify slices along different axis.

JavaScript

(np.take is equivalent of writing self.volume[idx], self.volume[:, idx] and self.volume[:, :, idx])

Finally, I want to assign a new slice in my volume along the axis :

JavaScript

This is where I need some help. I can’t figure out a cleaner way of doing this assignment. (I would like something as clean as np.take())

I have tried np.insert, np.insert_along_axis, np.put, np.put_along_axis… but I am clearly missing something out.

Any ideas ? :)

Have a great day

Advertisement

Answer

There may be a more elegant solution but the following should work:

JavaScript

Alternatively, you can try:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement