jeudi 23 novembre 2017

Random array from list of arrays by numpy.random.choice()

I have list of arrays similar to lstB and want to pick random collection of 2D arrays. The problem is that numpy somehow does not treat objects in lists equally:

lstA = [numpy.array(0), numpy.array(1)]
lstB = [numpy.array([0,1]), numpy.array([1,0])]

print(numpy.random.choice(lstA))   # returns 0 or 1
print(numpy.random.choice(lstB))   # returns ValueError: must be 1-dimensional

Is there an ellegant fix to this?




Aucun commentaire:

Enregistrer un commentaire