Mary
Mary

Reputation: 75

Numpy/Python zero division error

I don't know what is the problem here and I didn't realize how to find a way to resolve it. Actually, it gives the error ZeroDivisionError: division by zero. However there is nothing to be zero to divide to it, as far as I divided to 180 and it's not zero.

C1 = np.array([AA, north1, north1, north1, north1, D1, north1, north1, north1, north1]);
z = np.zeros((len(C1), 1));
C1 = np.concatenate([np.array(C1)[:,None], np.array(z)],axis=1);
B1 = C1 * [np.arange(np.cos(-90*np.pi/180), 0,np.sin(-90*np.pi/180)),np.arange(0, 1,0), np.arange(-np.sin(-90*np.pi/180),0,np.cos(-90*np.pi/180))];

P.S. Here I tried to do cosd:

np.cos(-90*np.pi/180)

Upvotes: 0

Views: 769

Answers (2)

vamshi45
vamshi45

Reputation: 1

This is happening because of below statement

np.arange(0, 1, 0)

The documentation of numpy.arange() does not say anything about having non-zero step.

https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html

Upvotes: 0

Barry McNamara
Barry McNamara

Reputation: 749

Your error is coming from np.arange(0, 1,0) which is trying to generate an array of values from 0 to 1 separated by 0. The function signature is numpy.arange([start, ]stop, [step, ]dtype=None) so you should have a nonzero step.

Upvotes: 2

Related Questions