1

i have a huge dataset as array in the format below

 #input array
    array([ 5.94911 , -1.0366  ,  3.25678 ])

i need to convert it to arrays in the format below.

array([[5.94911],
       [-1.0366],
       [ 3.25678]])

2 Answers 2

4
a = array([ 5.94911 , -1.0366  ,  3.25678 ])
dataset = np.array(a).reshape(-1,1)

This solution will not use additional memory for reshaping.

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

Comments

2

Try using np.vstack:

>>> a = array([ 5.94911 , -1.0366  ,  3.25678 ])
>>> np.vstack(a)
array([[ 5.94911],
       [-1.0366 ],
       [ 3.25678]])
>>> 

Or use a list comprehension:

>>> a = array([ 5.94911 , -1.0366  ,  3.25678 ])
>>> np.array([[i] for i in a])
array([[ 5.94911],
       [-1.0366 ],
       [ 3.25678]])
>>> 

But of course vstack is recommended.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.