-1

I have an array like this

ar = np.array([[0, 1, 0, 1, 0, 1, 0, 1],
       [0, 1, 0, 0, 0, 1, 1, 1]])

I want to get

array([[0., 0.],
       [1., 1.],
       [0., 0.],
       [1., 0.],
       [0., 0.],
       [1., 1.],
       [0., 1.],
       [1., 1.]])

If I do as below I get

ar.reshape(8,2)
array([[0, 1],
       [0, 1],
       [0, 1],
       [0, 1],
       [0, 1],
       [0, 0],
       [0, 1],
       [1, 1]])

My decision is

npar = np.zeros((np.asarray(ar).shape[1],np.asarray(ar).shape[0]))
npar[:, 0] = ar[0]
npar[:, 1] = ar[1]
npar
array([[0., 0.],
       [1., 1.],
       [0., 0.],
       [1., 0.],
       [0., 0.],
       [1., 1.],
       [0., 1.],
       [1., 1.]])

But is there more fast & convinient way?

Edward
  • 4,443
  • 16
  • 46
  • 81

1 Answers1

2

You simply need to take the transpose I think

np.transpose(ar)
Atul Shanbhag
  • 636
  • 5
  • 13