To simulate the flipping of a coin using NumPy, you can use the random.choice
function to randomly choose either "heads" or "tails" with a probability of 0.5 for each outcome. Here's an example of how you could do this:
import numpy as np
# Set the seed to ensure reproducibility
np.random.seed(0)
# Flip the coin 10 times
for i in range(10):
# Flip the coin
flip = np.random.choice(["heads", "tails"])
print(flip)
This will print out 10 random flips of a coin, with each flip having a 50% chance of being “heads” and a 50% chance of being “tails.”