Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert two dimension array to one dimension in python? [duplicate]

I have an array looks like this (two dimensions):

[[1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [0.]
 [0.]
 [1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [1.]
 [0.]
 [1.]
 [1.]
 [1.]
 [1.]
 [0.]
 [1.]]

How can I change it to: [1 1 1 1 ............1 0 1] I've been looking for solution for a whole afternoon but still got no idea, can someone give me some hint, thanks.

like image 333
wawawa Avatar asked Apr 30 '26 04:04

wawawa


1 Answers

On a numpy array a:

np.squeeze(a)

or

a.flatten()
like image 85
sdcbr Avatar answered May 01 '26 18:05

sdcbr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!