2

I have a pandas frame like this.

pd.DataFrame(data={'name':['name1','name2'],'vector':[np.array([1,2,3,4]),np.array([12,22,34,4])]}) 

I want to extract the vectors from the frame as a matrix like this.

np.array([[1,2,3,4],[12,22,34,4]]) 
0

2 Answers 2

3
np.array(df['vector'].tolist()) 

will result in

array([[ 1, 2, 3, 4], [12, 22, 34, 4]]) 

or

df['vector'].as_matrix() 

will result in

array([array([1, 2, 3, 4]), array([12, 22, 34, 4])], dtype=object) 
Sign up to request clarification or add additional context in comments.

Comments

2

df.vector.values should be the shortest.

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.