You can do that and it will work wereas the dimensional variable is fixed. If you expect to make a learnable vector which chooses parameters it will not work.
Aditionally, consider that those elements which aren’t “chosen” will does not backpropagate anything. You can always go for other ways like attention rather than this.