0

I have multiple different sized ndarrays (e.g. a = np.arange(3), b = np.arange(4) which I'd like to concat/stack to one ndarray res with the dtype ndarray:

> res
array([array([0, 1, 2]), array([0, 1, 2, 3])], dtype=np.ndarray)

Is there a way to achieve this?

2
  • That's not concatenating. That's an object array containing arrays, a bastardized list. Commented Aug 6, 2020 at 15:06
  • Why do you want to combine these arrays into one? What advantage would it have over a list? Commented Aug 6, 2020 at 16:11

1 Answer 1

0

Considering answer Merge two numpy array's of different shape into a single array you can use function concatenate from numpy module:

a = np.arange(3)
b = np.arange(4)
c = np.concatenate((a, b))
Sign up to request clarification or add additional context in comments.

2 Comments

this results to array([0, 1, 2, 0, 1, 2, 3]), not array([array([0, 1, 2]), array([0, 1, 2, 3])], dtype=np.ndarray)
Probably like that c = np.array([a,b], dtype=object) ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.