Skip to content
Advertisement

in Numpy, how to zip two 2-D arrays?

For example I have 2 arrays

JavaScript

How can I zip a and b so I get

JavaScript

?

Advertisement

Answer

You can use dstack:

JavaScript

If you must have tuples:

JavaScript

For Python 3+ you need to expand the zip iterator object. Please note that this is horribly inefficient:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement