1

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?

2 Answers 2

4

Try

np.roll(arr, -3)

Negative since you want to "move" elements to the left

Sign up to request clarification or add additional context in comments.

Comments

3

The command you are looking for is numpy.roll. It's the equivalent of Mathematica's Rotate command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.