convert State integers to onehotvector
I have a function that I use to convert two states into a one-hot vector and combine it all, and it works fine, but if I have a large L, for example, 3000, it will take time. The function works like this with L=3.
def OH3(x,end=2,len=3):
  x = T.LongTensor([[x]])
  end = T.LongTensor([[end]])
  one_hot_x = T.FloatTensor(len,l)
  one_hot_end = T.FloatTensor(len,l)
  first=one_hot_x.zero_().scatter_(1,x,1)
  second=one_hot_end.zero_().scatter_(1,end,1)
  vector=T.cat((one_hot_x,one_hot_end),dim=1)
  return vector

the output:
OH3(1)
tensor([[0., 1., 0., 0., 0., 1.]])

as I mentioned, the function works fine but slower for a large number of states, and I sent multiple states at once, like 500 states, it will take 4 second
Is there a faster way to do it?

Provided the assumptions made in the comments above are correct, this should be about as fast as you can get it done, one allocation of a new array and 2 assignment operations. Let me know if I'm missing something.
def OH3(x,end=2,len=3):
    vector = torch.zeros(2*len,dtype = int)
    vector[[x,len+end] = 1
    return vector

