Harmonics is the major power quality problem caused by nonlinear devices, leading to malfunction or operational halt of the system. Low-order harmonics increase vibration and heat generation in motors. Therefore, controlling harmonics in the output waveform is the prime target for industrial applications to avoid economic loss. Selective harmonic elimination pulse width modulation (SHEPWM) is one of the techniques used for eliminating or minimizing selected harmonics in the output voltage waveform. This paper utilizes the Newton-Raphson method and Dragonfly Algorithms to calculate optimum switching angles for a Cascaded H-bridge Multilevel inverter (CHBMLI). The algorithms use non-linear equations to calculate the Switching Angles of MLI. The Dragonfly algorithm requires several iterations to reach an optimum solution. For complex problems, this algorithm becomes computationally expensive and time-consuming. A lookup table addresses the limitation by offline training an Artificial Neural Network (ANN) to generate the optimum switching angle for a given modulation index. Neural Fitting Tool in MATLAB software is used to train the ANN model. The simulation is performed using MATLAB SIMULINK software for both 5-level and 7-level CHBMLI configuration. The Dragonfly algorithm-based ANN achieves THD 8.84% when the modulation index (M) equals 0.8 for a 7-level inverter and THD 14.91% for a 5-level inverter and effectively minimizes third and fifth-order harmonics.