1

I want an array that looks like this,

array([array([[1, 1], [2, 2]]), array([3, 3])], dtype=object)

I can make an empty array and then assign elements one by one like this,

z = [np.array([[1,1],[2,2]]), np.array([3,3])]
x = np.empty(shape=2, dtype=object)
x[0], x[1] = z

I thought if this possible then so should be this: x = np.array(z, dtype=object), but that gets me the error: ValueError: could not broadcast input array from shape (2,2) into shape (2).

So is the way given above the only way to make a ragged numpy array? Or, is there a nice one line constructor/function we can can call to make the array x from above.

2
  • Does this answer your question? Python numpy array of numpy arrays Commented Jun 11, 2020 at 1:56
  • No, I am not looking to append or concatenate a row/column. I want an array of other array objects which happen to be different shapes as shown in the example array x. Commented Jun 11, 2020 at 2:16

0

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.