I have a 48×365 element numpy array where each element is a list containing 3 integers. I want to be able to turn it into a 1×17520 array with all the lists intact as elements. Using
np.reshape(-1)
seems to break the elements into three separate integers and makes a 1×52560 array. So I either need a new way of rearranging the original array or a way of grouping the elements in the new np.reshape array (which are still in order) back into lists of 3.
Thanks for your help.
Is there a reason you can’t do it explicitly? As in:
You could also do it with
-1, it just has to be paired with another arg of the appropriate size.or
It occurred to me a bit later that you could also create a record array — this might be appropriate in some situations:
This can be reshaped in the original way you tried, i.e.
reshape(-1). Still, as larsmans’ comment says, just treating your data as a 3d array is easiest.