I have a string of some data. string[0] prints [31, 37, 3] : [0.12704417954091404] . I want to get the first array which is [31, 37, 3]
1 Answer
You are using a 3rd-party Python library, inspyred is an AI package for Python.
You appear to have a sequence of Individual instances; you'd look up the documentation and see what attributes such instances have. You are looking at the string representation of these instances, but you should be able to access various aspects directly.
The documentation states there are candidate, fitness, birthdate and maximize attributes; try these to see which one represents the list you seek.
A quick peek at the source code suggests you want the candidate attribute:
print string[0].candidate
When dealing with new objects in Python, you can always introspect them by using tools such as the type(), dir() and vars() functions, which tell you about the type of object you have, the methods the class defines, and the attributes the instance has.
stringis not type string in your case....<class 'inspyred.ec.ec.Individual'>type. I don't know what it is.