def decode_chars(idx, idx2chars): out = [] for line in idx: line = np.trim_zeros(line) out.append([idx2chars[item] for item in line]) return out