mercredi 18 octobre 2017

Is np.random.choice supposed to coerce?

I just noticed that if np.random.choice is used on a list that contains both strings and integers, then when integers are returned, they are coerced to strings. Is this intended behavior?

e.g.

>>>numpy.random.choice([1,2,3,4]) 1

but

>>>numpy.random.choice(['a',1,2,3,4]) '1'

I guess I can do my_list[np.random.choice(range(len(my_list)))], but that seems rather ugly.

Aucun commentaire:

Enregistrer un commentaire