Sometimes when creating new 2d arrays I end up with nested arrays rather than proper multidimensional ones. This leads to a number of complications such as misleading array.shape values.
What I mean is I end up with
array([array([...]), array([...])], dtype=object)
when I want
array([[...], [...]])
I'm not sure at which point in my code leads to the former scenario. I was wondering 1. what is good practice to avoid obtaining such arrays, and 2. any pragmatic fixes to revert it to the multidimensional form.
Regarding the latter, performing
np.array([list(i) for i in nested_array])
works but doesn't seem practical, especially if the dimensionality is higher.
ragged arraywarning or an error.[a.shape for a in nested_array]should tell you the shapes.np.stack(orvstack) may change it to multidimensional array - provided all component arrays match. It in effect treats the array as a list of arrays. If the shapes aren't consistent, this will raise an error - which may be useful information. Also this only applies to 1d object dtype arrays. If this doesn't help, you may need to ask a new question with details about how you create the problem array.