Skip to content
Advertisement

Combine and sort multiple array columns of values A and B where A is the common index

I have a n-long list of arrays. Each array consists of two columns: A) index values between 1-500 B) measured values

Each A column is slightly different (i.e. missing or having extra values).

I want to create single large array where i) there is single A (index) column consisting of all the index values and ii) all the B (measured values) columns appropriately sorted, so they are in the same row as the original index value. The missing values would be filled with nan or 0s.

Array examples:

JavaScript

Array of my dreams:

JavaScript

I tried creating an np.zeros() array and replaced the individual columns with small arrays and got stuck.

Then I tried getting all the A values upfront by np.vstack(), removed duplicates with np.unique, np.sort()ed them and got stuck again.

All input is much appreciated!

Advertisement

Answer

It’s quite simple using :

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement