The core of our method is the Magnetstein algorithm. We are going to summarize its main ideas briefly. To describe the theory behind the algorithm, first we need to introduce a new way of representing an NMR spectrum. Conventionally, spectra are represented as vectors, where the coordinates correspond to signal intensities in consecutive points of the chemical shift axis. Here, in contrast, we propose to view a spectrum as a probability distribution. Note that introducing this representation is a purely technical operation performed to be able to use the Wasserstein distance later on. We do not suggest any probabilistic interpretation of spectra. In practice, viewing spectra as probability distributions means storing the data as a set of pairs, where the first element corresponds to chemical shift and the second one corresponds to intensity. The intensities need to be normalized so that they sum up to 1. Note that this approach does not require the common measurement points for the analyzed spectra, and we can still meaningfully compare spectra with different chemical shift axes. Now, we can introduce the notion of the Wasserstein metric, 24 denoted as W , which is a distance function defined between the two probability distributions representing spectra, denoted as µ and ν. Intuitively, the Wasserstein distance is the lowest possible cost required to transform distribution µ into distribution ν by transporting probability mass along the horizontal axis. The cost of each move is equal to the amount of the transported mass (spectral intensity) multiplied by the distance on which the mass was transported. A total cost is the sum of the costs of all the individual moves.