How to create a few gates that can be optimized by the network

so I am designing a network that has input in the format as [x1,x2,x3,…,xn], each vector xi has length k. Now, before these features are fed into my network, I want to add a layer of gates to select from these features. So I will have gates G1,…Gn, each gate is simply a 1D variable. How should I implement it that the gates can be optimized by gradient descend? Thanks.