1

I selected several rows of the first column and used both .values and as_matrix() to convert it to numpy array.

x1 = df.iloc[[1,3,4,64,34], 0]

The dimension of the each element in the dataframe is a (3, 3, 5) numpy array. I would like to output a (5, 3, 3, 5) numpy array from the dataframe. However when I use .values, i get a (5, ) shape array with a dtype =unit8 at the end of each element. How can I go about fixing this?

2
  • must have been by accident Commented Jun 1, 2017 at 21:08
  • Thanks, appreciate it Commented Jun 1, 2017 at 21:08

1 Answer 1

1
df = pd.DataFrame(dict(A=[np.ones((3, 3, 5))] * 5))

A = np.array([a.tolist() for a in df.iloc[[0, 1, 2, 3, 4], 0]])

print(A.shape)

(5, 3, 3, 5)
Sign up to request clarification or add additional context in comments.

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.