0

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.

scribe
  • 673
  • 2
  • 6
  • 17
  • Does this answer your question? [Python numpy array of numpy arrays](https://stackoverflow.com/questions/31250129/python-numpy-array-of-numpy-arrays) – Raghul Raj Jun 11 '20 at 01: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`. – scribe Jun 11 '20 at 02:16

0 Answers0