batch = np.array([1,1,1,1,1])
batch = tuple(t for t in batch)#转换为元组形式
# print(batch)
inputs = {'slot_labels_ids': batch}
out_slot_labels_ids = np.array([2,2,2,2,2])
for i in range(5):
out_slot_labels_ids = np.append(out_slot_labels_ids, inputs["slot_labels_ids"], axis=0)
out_slot_label_list = [[] for _ in range(out_slot_labels_ids.shape[0])]
a = out_slot_labels_ids.shape[0]
print(a)
print(out_slot_label_list)
输出:
30
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
本文探讨了使用NumPy库进行数组操作的方法,包括如何将数组转换为元组,以及如何通过append函数沿轴方向扩展数组数据。通过具体代码示例展示了数据处理过程,并输出了扩展后的数组形状及相应列表。
1924

被折叠的 条评论
为什么被折叠?



