Numpy random choice of tuples
问题 I'm having trouble to create an array of random choices, where a choice is a tuple. I get the error: a must be 1-dimensional Here is an example: choices = ((0,0,0),(255,255,255)) numpy.random.choice(choices,4) Is there any other way to do this? Expected result: a numpy array consiting of 4 elements randomly picked from the choices tuple. ((0,0,0),(0,0,0),(255,255,255),(255,255,255)) 回答1: Use choice to choose the 1dim indices into the array, then index it. In the example you provided, only the