The following code creates two arrays, A and B. A is actually a numpy array of arrays, only because its subarrays don't have the same length.
arr1 = np.arange(2,7)
arr2 = np.arange(5,7)
arr3 = np.arange(7,9)
A = np.array([arr1, arr2, arr3])
arr1 = np.arange(2,4)
arr2 = np.arange(5,7)
arr3 = np.arange(7,9)
B = np.array([arr1, arr2, arr3])
Now, my question is how to force B also to be an array of arrays even if its subarrays have the same length?
np.empty(3, dtype=object)(which will be filled withNone), and assign the individual arrays to it.arr[:] = [arr1, arr2, arr3]might work (if broadcasting doesn't get in the way).AandBswitched.Bis the standard 2D array, andAis an array or arrays in your exampleB[:]=np.ones((3,2))has problems.B[:]=list(np.ones((3,2)))does not.