ValueError: Input contains NaN, infinity or a value too large for dtype(‘float32’).

np.all(np.isfinite(mat))

Here is what the above code is Doing:
1. We’re creating a function that takes in a matrix and returns a boolean.
2. We’re using the numpy package to check if all the values in the matrix are finite.
3. We’re returning the result of the check.