I think it would be easier to slice along the dimension you want and then stack. Creating a kernel makes no sense as you will be wasting computation and memory (applying the identity kernel).
Edit:
I assumed that you were talking about image channels but it’s not the case, my bad.
Have a look at this library
https://torchgeometry.readthedocs.io/en/latest/filters.html 13
they implement several filters.