Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I encountered errors (TypeError: only 0-dimensional arrays can be converted to Python scalars) with vectorized use of the single valued functions, that is, when instead of passing a single number (scalar) as argument, the user gives an array of numbers. In fact, the functions expect an array of values already but in this case the vectorized form has as input a two dimensional array. An example of use that returns the error is passing the matrices from
numpy.meshgridto make 3D plots of the Ackley function.The reason for this issue seems to be that functions from Python's standard math library (like exp, sqrt, cos), which
landscapesuses, are not designed to work on arrays; they only operate on single, scalar values. When we pass the X and Y matrices from meshgrid to the function, we are trying to apply these scalar functions to entire arrays, which causes the TypeError. The solution is to use the equivalent functions from the NumPy library (np.exp, np.sqrt, np.cos), which are specifically designed to operate element-wise on arrays.Since I needed it, I made some minimal changes myself. I make them available here. Of course, there can be many good reasons for not wanting the merge. Feel free to reject it.