0

I load a feather file throught python 3.7 that contains arrays inside an array, example:

print(X)

array([array([1, 2]), array([3, 4])])

and i'm trying to convert X to:

array([[1, 2],
       [3, 4]])

How can i do that?

Thank You.

3
  • 1
    Numpy already do that. At least the last version (1.20). Indeed, np.array([np.array([1, 2]), np.array([3, 4])]).shape is (2,2) Commented Apr 26, 2021 at 11:59
  • Otherwise this could help numpy.org/doc/stable/reference/generated/… x = np.asarray(x) Commented Apr 26, 2021 at 12:11
  • 1
    @JérômeRichard, you made this array from a list of arrays. The OP has an object dtype array, which is different. Commented Apr 27, 2021 at 2:44

1 Answer 1

1

Use np.stack:

import numpy as np
np.stack(X)
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.