def get_table_and_array_for_set_of_dicts(dicts):
for j in range(len(dicts)):
if not j:
all_keys = np.array([i for i in dicts[j].keys()], dtype=np.uint64)
else:
all_keys = np.concatenate([all_keys, np.array([i for i in dicts[j].keys()], dtype=np.uint64)])
unique_keys = sorted(set(all_keys))
# The sorted is so that the index of 0 will always be 0
index_lookup_table = create_index_table(np.array(sorted([np.uint64(key) for key in unique_keys]), dtype=np.uint64))
array = np.zeros(shape=[len(dicts), len(unique_keys)], dtype=np.uint64)
for square_num, dict in enumerate(dicts):
for key, value in dict.items():
array[square_num][
khash_get(ffi.cast("void *", index_lookup_table), np.uint64(key), np.uint64(0))] = np.uint64(value)
return index_lookup_table, array
评论列表
文章目录