I want to divide two one-dimensional arrays element-wise. There will be divisions by zero, but I still want to do the division. The result of div/0 is irrelevant, I'll handle that later.
Why does this error occur? And why does it stop occurring after I have checked the values of my arrays? How can I avoid this error when running my code?
>>> a=numpy.array([1, 2, 3, 0, 0])
>>> b=numpy.array([5, 3, 1, 0, 0])
>>> a/b
Traceback (most recent call last):
File "<pyshell#57>", line 1, in <module>
a/b
File "C:\Program Files (x86)\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
file.write(warnings.formatwarning(message, category, filename,
AttributeError: 'NoneType' object has no attribute 'write'
>>> a
array([1, 2, 3, 0, 0])
>>> b
array([5, 3, 1, 0, 0])
>>> a/b
array([ 0.2 , 0.66666667, 3. , nan, nan])