You need to normalize a NumPy array so that the values range between 0 and 1. How would you achieve this?
- Using Exponential Transformation: np.exp(arr)
- Using Min-Max Scaling: (arr - arr.min()) / (arr.max() - arr.min())
- Using Square Root Transformation: np.sqrt(arr)
- Using Standardization: (arr - arr.mean()) / arr.std()
To normalize a NumPy array to the range [0, 1], you should use Min-Max Scaling. It involves subtracting the minimum value of the array from each element and then dividing by the range (the difference between the maximum and minimum values). This method scales the data linearly to the desired range.
Loading...
Related Quiz
- You are required to implement a feature where you need to quickly check whether a user's entered username is already taken or not. Which Python data structure would you use for storing the taken usernames due to its fast membership testing?
- How can you secure sensitive information, like API keys, in a Flask or Django application?
- The ____ attribute in a class is used to define its metaclass.
- What happens when a function doesn't have a return statement?
- What is the primary purpose of Flask's route() decorator?