Reputation: 21961
I have the following Numpy array:
arr = np.array([0.3, 3.5, 12.0, 2.9, 11.0, 23.0])
I want to reorder the array so it starts at the 4th position, followed by the items after the start position in order, followed by the items before the start position. I.e.
[2.9, 11.0, 23.0, 0.3, 3.5, 12.0]
How can I do this without a for loop?
Upvotes: 1
Views: 289
Reputation: 3253
Try
np.roll(arr, -3)
Negative since you want to "move" elements to the left
Upvotes: 4
Reputation: 7941
The command you are looking for is numpy.roll
. It's the equivalent of Mathematica's Rotate
command.
Upvotes: 3