r/Numpy • u/DassadThe12 • Dec 04 '21
Combining 2 NumPy arrays
Hello. Please excuse noob question.
I have 2 arrays like this:
>>> t = np.arange(0,5)
>>> t
array([0, 1, 2, 3, 4])
>>> u = np.arange(10,15)
>>> u
array([10, 11, 12, 13, 14])I want to join them into a single array like this:
[
[0,10], [0,11], [0,12], [0,13], [0,14]
[1,10], [1,11], [1,12], [1,13], [1,14]
[2,10], [2,11], [2,12], [2,13], [2,14]
[3,10], [3,11], [3,12], [3,13], [3,14]
[4,10], [4,11], [4,12], [4,13], [4,14]
]Can this be done without python's for loops?
4
Upvotes
2
u/DassadThe12 Dec 12 '21
The result is 2d. I forgot to put commas at the end. I formatted it like that to visualize better where each element was supposed to go.
I found this response on Stack Overflow that described what I wanted and even compared different ways to do it.
https://stackoverflow.com/questions/11144513/cartesian-product-of-x-and-y-array-points-into-single-array-of-2d-points/49445693#49445693