'Converting H/T to 0/1 binary array [closed]

I’ve loaded a sample using the code:

Data = np.load(sample_1.npy)

I need to convert the data points from H/T (coin tosses) to 0/1 (binary array). Not sure what code would work for this? I’ve tried googling answers and they haven’t worked.



Solution 1:[1]

If it's an array with "H" and "T" as values, you could try that:

Data = np.array([0 if x == "H" else 1 for x in Data])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cubix48