Numpy, Runtimewarning: Invalid Value Encountered In Sqrt
Solution 1:
the square root function, by definition, gives the positive (also called principle) root of the number it's square rooting.
the "negative square root" is part of a more general set of solutions to the equation a^n = b, where n is the degree of the root, b is the number you're taking the square root of, and a is the solution (a and b might be complex).
the point is that the "general square root" is ambiguous because it has a bunch of solutions for one input. it's not a (mathematical) function. numpy uses the standard that everyone uses, which is the positive/principle solution.
if you want a sphere, you can make two half spheres and flip one of them upside down. (I don't know how to fill in the gap between them :( )
as far as the runtime warning, you're taking the square root OF a negative number at the corners of the grid, where there's no (real) solution to the circle. there should be no solution there, since the circle doesn't exist there. (if you print zs, you should see NaNs.)
Post a Comment for "Numpy, Runtimewarning: Invalid Value Encountered In Sqrt"