I am trying to use numpy optimized in-built functions to generate thermometer encoding. Thermometer encoding is basically generating n amount if 1\'s in a given len
not much different, listcomp inside an array creation function
temps = [1,2,4,1]
tlen = 8
np.stack([np.pad(np.ones(t), (0, tlen-t), 'constant') for t in temps])
Out[66]:
array([[ 1., 0., 0., 0., 0., 0., 0., 0.],
[ 1., 1., 0., 0., 0., 0., 0., 0.],
[ 1., 1., 1., 1., 0., 0., 0., 0.],
[ 1., 0., 0., 0., 0., 0., 0., 0.]])