Víctor Varela
Víctor Varela

Reputation: 43

How to flatten an array like this using Python?

I have this array here:

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

and I want to transform it like this:

>>>[['1' '2' '3'] ['4' '5' '6'] ['7' '8' '9'] ['13' '14' '15'] ['10' '11' 12'] ['16' '17' '18']]

i'm using Numpy's .flatten(), but it is not working

thanks

Upvotes: 3

Views: 73

Answers (1)

Silver
Silver

Reputation: 1468

Try:

a.transpose(1, 0, 2).reshape(-1, 3)

Upvotes: 3

Related Questions