samedi 15 mai 2021

Pairing Adjacent Values in a Numpy Array

Say I have an array of values array = [0.0, 0.2, 0.5, 0.8, 1.0], and I want to pair adjacent values into a secondary list paired_array = [[0.0, 0.2], [0.2, 0.5], [0.5, 0.8], [0.8, 1.0]], is there an easy way of doing that in numpy?

For context, the pairs represent probability ranges which I will be using to randomise the values in a numpy array of type string. For example string_array = ['Fe', 'Pt', 'Fe', 'Pt', 'Fe', 'Pt', 'Fe', 'Pt'] may become something like randomised_array = ['Pt', 'Fe', 'Pt', 'Pt', 'Pt', 'Pt', 'Fe', 'Fe']. The ranges represent the probability a value is 'Pt' or 'Fe' in this case.




Aucun commentaire:

Enregistrer un commentaire