0

I am trying to append a number to a numpy array. This seems like a simple task (and I have seen and tried this), but somehow they are not being appended.

newlist = np.array([])

for i in range(15, 15+number):

    number =  myList[i][1];
    np.append(newlist,[number]) 
    print newlist

I believe it might have to do with the fact that myList is a normal list that contains both strings and numbers. Should I cast it to a number first or something? myList:

[['started recording', '38:20.4', '\r\n'], ['stopped recording', '42:46.1', '\r\n'], ['participant number', '41', '\r\n'],...
5
  • 2
    Some assignment: newlist = np.append(newlist,[number]) Commented Oct 9, 2016 at 14:44
  • Take another look at the docstring for numpy.append. In particular, see the "Returns" section, which notes that append does not work in-place. Commented Oct 9, 2016 at 14:45
  • Oh my, of course. That is too silly of me. Thanks! Commented Oct 9, 2016 at 14:47
  • 1
    Don't worry, you're not the first to make this mistake. Perhaps the first line of the docstring should be "Copy arr and append values to the end.", or something like that. Commented Oct 9, 2016 at 14:49
  • It's especially confusing because the normal list doesn't require this. Do you want to post this as an answer? Commented Oct 9, 2016 at 18:47

0

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.