2

Let's say I have a 2-d numpy array with 10 rows

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?

For example a first call to the queue.get() would retrieve [23865., 527971.1875 ] and a second call would retrieve [23745., 540303.0625 ]

2
  • do you want each item put in the queue or each row in your array? Commented Feb 18, 2016 at 14:20
  • The documentation page shows that only the put() method allows inserts, so I would say no. It also mentions a thread-safe and lock-less deque type on the same page which does allow you to provide an entire iterable to the constructor. Commented Feb 18, 2016 at 14:21

1 Answer 1

6

You can use the map keyword to avoid iterating over the array:

map(queue.put, myArray)

or in python 3.x:

list(map(queue.put, myArray))

Sign up to request clarification or add additional context in comments.

3 Comments

that's what I was looking for, should I delete the question as duplicate?
I'm not sure your question is a duplicate to an existing one. I wouldn't delete it unless someone would tell you it is a duplicate
This doesn't work in Python 3 since it does lazy evaluation of maps. You would need to do some ugly thing like list(map(queue.put, myArray)) but at that point I guess a loop is justifyable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.