[英]Python - How to place a whole numpy array in Queue.Queue all at once but retrieve each row separately
Let's say I have a 2-d numpy array with 10 rows 假设我有一个10行的2维numpy数组
for example 例如
array([[ 23425. , 521331.40625],
[ 23465. , 521246.03125],
[ 23505. , 528602.8125 ],
[ 23545. , 531934.75 ],
[ 23585. , 534916.375 ],
[ 23625. , 544971.9375 ],
[ 23665. , 544707.5625 ],
[ 23705. , 532729.25 ],
[ 23745. , 540303.0625 ],
[ 23865. , 527971.1875 ]])
Is there a way to place that whole array in a queue (from python's collections) all at once, without iterating over the array and using put()
for each row, and then be able to retrieve each row separately using the queue.get()
function? 有没有一种方法可以将整个数组一次性全部放入队列(来自python的集合),而无需遍历数组并为每一行使用
put()
,然后可以使用queue.get()
分别检索每一行。 queue.get()
功能?
For example a first call to the queue.get()
would retrieve [23865., 527971.1875 ]
and a second call would retrieve [23745., 540303.0625 ]
例如,对
queue.get()
的第一次调用将检索[23865., 527971.1875 ]
,第二次调用将检索[23745., 540303.0625 ]
You can use the map
keyword to avoid iterating over the array: 您可以使用
map
关键字来避免迭代数组:
map(queue.put, myArray)
or in python 3.x: 或在python 3.x中:
list(map(queue.put, myArray))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.