Fixing Python Numpy TypeError: ufunc ‘isfinite’ not supported for the input types

Python Numpy TypeError: ufunc ‘isfinite’ not supported for the input types is an error which occurs when you work with an array that has a dtype of object.

Today, I will explain in detail why this error is happening and how to fix it in the most efficient way possible.

Exploring the Python Numpy TypeError: ufunc ‘isfinite’ not supported for the input types

This is an error which occurs when you work with an array that has a dtype of object.

Do not mix between errors. Make sure the error message looks like the error message bellow

                                                                       #
TypeError: ufunc 'isfinite' not supported for the input types
                                                                       #

In the sections bellow we will explain the source of the problem and propose many possible fixes.

The Method that solved my issue : Changing the dtype of the array

This is an error which occurs when you work with numpy arrays in Python and have an array that has a dtype of object.

The error mentions ufunc ‘isfinite’, ufuncs are functions that operates on ndarrays in an element-by-element basis, which supports standard features and features like array broadcasting, type casting …

So, if we assume I have an array myarray of type object

                                                                       #
myarray = ...
                                                                       #

and use it with a ufunc that does not accept objects you are going to run to the error we are trying to solve.

So, before you use or plot it for example etc. You should change its dtype.

If you have a similar error to the one I am trying to solve, you should change the dtype to float

                                                                       #
myarray = np.array(myarray, dtype=float)
                                                                       #

I hope changing the dtype of the array to float fixed your issue, thank you for reading this blog post to the end.

Summing-up : 

I hope this article has helped you solve the error : Python Numpy TypeError ufunc isfinite not supported for the input types , If you like our efforts, please consider donating to our Kofi account.

Thank you for reading my blog post to the end, If you want to learn more about the Python programming language, check out the official Python Documentation : https://docs.python.org/3/