I have an array of numbers, which I would like to replace with a string depending on some condition. I can replace them with numbers:
d_sex = rand(10)
d_sex[d_sex > 0.5] = 1
d_sex[d_sex <= 0.5] = 0
d_sex
But I cannot do d_sex[d_sex>0.5] = "F". How would I do that in the most pythonic way? Would I create an empty string array? I am looking for something similar to Julia's:
d_sex = rand(50)
s_sex = ifelse(d_sex .> 0.5, "M", "F")
[d_sex s_sex]
numpyarrays?d_sex = int(random.random() + 0.5). If that's not what you're looking for try adding more details to your question