2

How do I get numpy array into python list?

looking for ('foo', 1, 2, 3, 4) series is a numpy array

symbol = 'foo'

def rowp (symbol,series):
            rowp=[]
            series = series[0:4]
            ss = series.tolist     
            rowp.append(symbol)     
            rowp.append(ss)      
            print rowp

I get error:

['foo', <built-in method tolist of numpy.ndarray object at 0x05D07D40>] 
2
  • ok, But now I get ('foo', [1,2,3,4]) .....its late here....I thought I had called it..... How do I get ('foo', 1, 2, 3, 4) Commented Sep 12, 2011 at 0:32
  • use rowp.extend instead of append. Create a new question for these things Commented Sep 12, 2011 at 0:34

1 Answer 1

6

As you can already see by the error message, tolist [docs] is a method. That means you have to call it:

ss = series.tolist()

Update: Use extend instead of append:

rowp.extend(series.tolist())

Btw, the result you get is not an error.

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.