One-Hot Encoding of Nominal Values
Data Preparation & Feature Engineering DS practice problem on Onlearn.
Difficulty: easy.
Topics: Understanding One-Hot Encoding of Nominal Values, One-Hot Encoding, Dummy Variable Trap, Sparse Matrix Representation, Numpy Broadcasting, Nominal Feature Mapping, Data Preprocessing, Feature Engineering, Numerical Computing, Statistical Data Representation, Machine Learning Pipelines, Categorical Data Encoding, Array Manipulation, Dimensionality Expansion, Vectorization Techniques, Input Transformation.
Write a Python function to perform one hot encoding of nominal values. The function should take in a 1D numpy array x of integer values and an optional integer n col representing the number of columns for the one hot encoded array. If n col is not provided, it should be automatically determined from the input array.