I have a list of [float, (float,float,float..) ] … Which is basically an n-dimensional point along with a fitness value for each point.
For eg.
4.3, (2,3,4)
3.2, (1,3,5)
.
.
48.2, (23,1,32)
I wish to randomly sample one point based upon the fitness values. I decided the best way to do this would be to use numpy.random.choice(range(n), 1, plist[:,:1,:1])
However, i need to convert this into an numpy array, for which i tried
>> pArr = np.array( plist )
ValueError: setting an array element with a sequence
I got the same error for np.asarray(plist) as well.. any suggestions??
The following should work:
with
initial_list = [[4.3, (2, 3, 4)], [3.2, (1, 3, 5)], ...]. Note that we need to transform each item ofinitial_listinto a tuple for that trick to work, else NumPy cannot recognize the structure.Your fitness entries are now accessible as
A['fitness'], with the corresponding points asA['point']. If you select a list of actual fitness entries,indices, the corresponding points are given byA['point'][indices], which is a simple(n,3)array.