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

2
  • I would really like to see the for loop solution. Commented Mar 9, 2022 at 15:51
  • 1
    @MichaelSzczesny it is like this-: 1. i corvert into list. then make list of lists. and then convert it to numpy array Commented Mar 9, 2022 at 16:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.