11

I have theee arrays, and want to combine them

import numpy as np
a = np.array([[1,2,3],[4,5,6]])
b = np.array([[7,8,9],[10,11,12]])
c = np.array([[13,14,15],[16,17,18]])

To get:

array([1,2,3,7,8,9,13,14,15, 4,5,6,10,11,12,16,17,18])

What is the function for this ?

Thanks :)

2 Answers 2

15

Stack those horizontally with np.hstack and flatten with np.ravel -

np.hstack(( a,b,c )).ravel()
Sign up to request clarification or add additional context in comments.

Comments

9
d=np.concatenate((a, b,c), axis=None)

The None parameter ensures that the arrays are flattened before concatenation (the gluing of arrays).

2 Comments

Please, explain why&how your answer works so that It can be more useful to less experiences programmers
The user has provided the input and the output expected, my code gives the output required

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.