Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Implement roll(a) that circularly shifts a 1-D array left by one position: out[i] = a[(i + 1) % n].
Do not call np.roll. Use index arithmetic.
Example:
roll(np.array([1., 2., 3., 4.])) -> [2., 3., 4., 1.]
roll(np.array([1., 2., 3., 4.]))
[2. 3. 4. 1.]
Each index takes the next element; last wraps to first.