title: One-hot encoding of decimals with a fixed precision in python/numpy
body: <p>In Python, I would like to achieve a <em>one-hot</em> encoding of decimal numbers with precision until <code>10^{-3}</code>. Given that my input fractions are, e.g., <code>interval = [0.433,0.223,0.111]</code>, it would produce a stack of one-hot vectors for each number in interval. So for the first float number <code>0.433</code> we should get <code>4 ---&gt; 0 0 0 0 1 0 0 0 0 0</code> , <code>3 ---&gt; 0 0 0 1 0 0 0 0 0 0</code>, <code>3 ---&gt; 0 0 0 1 0 0 0 0 0 0</code> and then concatenate the three obtaining a 30 dimensional one-hot array.</p>
  <p>Also, I'm wondering about this: even if the input numbers are, let's say, <code>[0.4,0.2,0.1]</code>, is there a way to apply the same technique as before? Like considering mathematically equivalent numbers <code>[0.400,0.200,0.100]</code>?</p>
  <p>EDIT:</p>
  <p>This is my proposed attempt. I'm not sure this is the best way to accomplish the result, adn additionally this not solves the case where we are given for example <code>[0.4, 0.2]</code> but we want to interpret it as <code>[0.400, 0.200]</code> .</p>
  <pre><code>def encode_digits(floats: list):
              
      decimals = []
      
      for f in floats:
          
          decimals.append(str(f).split('0.',1)[1])
          
      one_hot = []
          
      for i in range(2):
          
          for j in range(3):
              
              temp =np.zeros(10)
              
              temp[int(decimals[i][j])] += 1
              
              one_hot.append(temp)
              
      return np.array(one_hot).reshape(-1)
  </code></pre>