0

I have a dictionary where each item is 1D python array and I would like to convert it into a 2D numpy array.

For example, my dictionary is

a = {"tom": np.random.uniform(size = 100), "bill": np.random.uniform(size=100)}

and I would like to store in a 2D numpy array with shape (100,2). Have you any suggestions?

1
  • 1
    There are various ways of combining a list or tuple of arrays. Commented Sep 12, 2021 at 20:20

2 Answers 2

3

You can stack the values:

np.stack(a.values(), axis=-1)
Sign up to request clarification or add additional context in comments.

Comments

2

You can column_stack the values:

np.column_stack(a.values()).shape
# (100, 2)

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.