Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'numpy.ndarray' object has no attribute 'append'

I am trying to run the code presented on the second page:

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/video-lectures/lecture-20/lec20.pdf

At the bottom of the code you have to add these lines:

simFlips(100,100)  show() 

Here is the error that I get when I run it on ubuntu:

Traceback (most recent call last):   File "coin.py", line 36, in <module>     simFlips(100,100)   File "coin.py", line 16, in simFlips     diffs.append(abs(heads - tails)) AttributeError: 'numpy.ndarray' object has no attribute 'append' 

Please tell me what I'm doing wrong that gives me the last error. Thanks in advance!

like image 811
vahshi Avatar asked Dec 07 '11 01:12

vahshi


People also ask

Has no attribute append Python?

The Python "AttributeError: 'NoneType' object has no attribute 'append'" occurs when we try to call the append() method on a None value, e.g. assignment from function that doesn't return anything. To solve the error, make sure to only call append() on list objects.

How do I add items to a NumPy array?

You can add a NumPy array element by using the append() method of the NumPy module. The values will be appended at the end of the array and a new ndarray will be returned with new and old values as shown above. The axis is an optional integer along which define how the array is going to be displayed.


1 Answers

Use numpy.concatenate(list1 , list2) or numpy.append() Look into the thread at Append a NumPy array to a NumPy array.

like image 154
Arpita Biswas Avatar answered Sep 28 '22 19:09

Arpita Biswas