I have a function that sometimes gives me a list of lists where the nested lists sometimes only have one item, such as this one:
a = [['1'], ['3'], ['w']]
And want to randomly select one item from that main list a
. If I try to use np.random.choice
on this list, I get a ValueError: a must be 1-dimensional
.
But if the list were instead:
b = [['1'], ['3'], ['w', 'w']]
Then using np.random.choice
works perfectly fine. Why is this? And how can I make it so that I can randomly select from both types of lists?