Ranjan Kumar February 2016

np.poly1d() exclude printing variable(x), if coefficient is 0 or -0, but it includes if it is -0.0

numpy.poly1d() exclude printing variable(x) if coefficient is 0 or -0, but it includes if it is -0.0

Example:

print np.poly1d([1,-0.0,3])
   2
1 z + 3

print np.poly1d([1, 0, 3])
   2
1 z + 3

print np.poly1d([1, -0.0, 3], variable='z')
   2
1 z - 0 z + 3

Why it is so?

Answers


MSeifert February 2016

Well it is because python saves (or at least prints) these zeros differently:

print(0)
0
print(-0)
0
print(0.0)
0.0
print(-0.0)
-0.0

and numpy only ignores coefficients that are not 0 but it ignores the decimal places if they are only zeros. (see source).

This means that everything except -0.0 is evaluated as 0 and not shown.

Post Status

Asked in February 2016
Viewed 3,660 times
Voted 9
Answered 1 times

Search




Leave an answer