Monday 15 March 2021

Concatenate Different Sized ndarrays

Simple data structure question, but I cannot find the correct python syntax to do so. Given numpy arrays (in my actual use, to be read from text files with np.loadtxt) such as

A=[[1,2],[3,4]]
B=[[5,6],[7,8],[9,10]]
C=[[11,12],[13,14],[15,10]]

i.e., 2D, but all different lengths in one dimension. How can I combine these into a single 3D array, such that combinedArrays[0] returns A, or combinedArrays[:,0] returns all the first rows, etc?

I have tried np.append, np.stack, and np.concatenate, but none of these have worked. I could expand the smaller matrices with zeros and just top fill, but then that is carrying around a lot of extra zeros for no reason.



from Concatenate Different Sized ndarrays

No comments:

Post a Comment