sách gpt4 ăn đã đi

python - 将队列转储到python中的列表/数组中

In lại 作者:太空狗 更新时间:2023-10-29 19:31:30 25 4
mua khóa gpt4 giày nike

我正在运行多个线程并在队列中收集结果。我想将它转储到数组或列表中,以便我可以进行索引并检索这些结果。队列中的每个元素都是一个维度为 n 的数组。我想访问这些数组。请告诉我,我该怎么做?

 def dump_queue(model_queue):
queue_list = []
for i in iter(model_queue.get,'STOP'):
queue_list.append(i)
return queue_list




aux_model=train_svm(np.array(trainExample),np.array(trainLabel))
model_queue.put(aux_model.coef_)

因此数组是svm的学习模型参数。 model_queue 在线程之间共享。我想访问每个模型参数向量,而不是模型参数的每个条目。

câu trả lời hay nhất

您已经完成了并行部分,只想在列表中获取结果,是吗?然后尝试:

list(my_queue.queue)

ví dụ:

from queue import Queue

q = Queue()
for i in range(5):
q.put(i)

l = list(q.queue)
in(l)

Đầu ra:

[0, 1, 2, 3, 4]

关于python - 将队列转储到python中的列表/数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17718265/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress