0

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]

6
  • Do you want to get it as a string or as an array of integers? Commented May 10, 2014 at 6:36
  • anything. but I am expecting array. Commented May 10, 2014 at 6:38
  • Could you run the command type(string[0]) and tell us the result? Commented May 10, 2014 at 6:39
  • i think string is not type string in your case.... Commented May 10, 2014 at 6:39
  • @compie It's <class 'inspyred.ec.ec.Individual'> type. I don't know what it is. Commented May 10, 2014 at 6:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.