You’re right. Here is DenseArray code, and it takes only 25ms
%%time
import torch
import numpy as np

class DenseArray:
    def __init__(self):
        self.array = np.zeros(1024)
        self.idx = 0;
        
    def clear(self):
        self.array.fill(0.0)
        self.idx = 0
        
    def addFloat(self, v):        
        self.array[self.idx] = v
        self.idx += 1
        
    def addCategorical(self, idx, categorySize):
        #assert (idx < categorySize)
        #assert (0 <= idx)
        self.array[self.idx+idx] = 1.0
        self.idx += categorySize

da = DenseArray()
for i in range(1024*16):
    da.clear()
    da.addFloat(5.0)
    da.addCategorical(i%100,100)