Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between `numpy.fix` and `numpy.trunc`?

Tags:

python

numpy

Aside from the additional functionality that trunc possesses as a ufunc, is there any difference between these two functions? I expected fix to be defined using trunc as is fairly common throughout NumPy, but it is actually defined using floor and ceil.

If the ufunc functionality is the only difference, why does fix exist? (Or at least, why does fix not just wrap trunc?

like image 298
QuaternionsRock Avatar asked Aug 12 '26 11:08

QuaternionsRock


1 Answers

There is no difference in the results. Both functions, though implemented differently internally, produce the same results on the same set of input types and produce the same results in both value and type. There is no good reason for having both functions, particularly when one will work more slowly and/or take more resources than the other and both must be maintained for as long as numpy survives. Quite frankly, this is one problem with Python and many other design-by-committee projects, and you see debates over this trunc/fix issue in other language and library development projects like Julia.

like image 162
Ken Avatar answered Aug 14 '26 11:08

Ken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!