2

i have a following numpy array. array([11, 11, 51, 11, 11, 51, 51, 11, 11, 51]) which has a shape (10,)

I want to make it to array([[11], [11], [51], [11], [11], [51], [51], [11], [11], [51]]) and shape should be (10,1).

One way to do it using the for loop, but i think which is not good way to get this done.

can someone suggest a more proper way?

thanks

Coder
  • 1,129
  • 10
  • 24

1 Answers1

4
a = np.array([11, 11, 51, 11, 11, 51, 51, 11, 11, 51])
a = a.reshape(-1,1)

(-1,1) means that you want the second shape to be exactly 1 and the first shape will be inferred from the length of the array.