mlclass-ex4 solved in vectorized format