Python Puzzle 2 Solution
This was a nice fun puzzle and I loved the posted solutions as comments and some people were a little bit shy and sent the solution over DM. They were all great!
Thank you very much!
Now, my solution and why it matters...
[5 min]
I solved with Python
Both NumPy and TensorFlow have a sum method on their array/tensor class that can be applied for all indices, or by rows or by cols.
The parameter 'axis' is how you define in which dimension the sum is applied.
For rows in a matrix: axis=1
The argmax method returns the index of the highest value in the array.
My solution could be simplified to just:
index = m.sum(axis=1).argmax()
Why is this puzzle important?
Some people knew the solution by heart and that's because this problem is very common in the Machine Learning world.
For example, on Audio Classification like we can see here:
For audio, let's suppose you receive 3 seconds of audio to find events and your model know about 3 classes : dog, cat, background noise
The model will frame the audio in smaller time slices (eg: 1s) and then return one array of probabilities for each frame. Your goal now is find, along the 3 seconds, what is the class with higher probability
The puzzle is a simplified version of this problem.
Why is solving coding problems important?
Programming is like speaking a different language
Solving these problems is a good practice on this "new" language
Of course some puzzles are too hard!
The same way that some Shakespeare's poems are too hard to understand
But with some practice we start to have a better understanding
I'll keep posting these puzzles when I come by them
If you have suggestions, just send me a DM!