From 6b623d3a302acd5914adfceaaea289b22945f4f5 Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Sat, 7 Oct 2023 18:17:10 -0400 Subject: [PATCH] Reduce numpy array concatenations --- physics.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/physics.py b/physics.py index a779c3b..f174b59 100644 --- a/physics.py +++ b/physics.py @@ -4,13 +4,10 @@ import numpy as np G = 6.674e-11 -def rotate(a: np.ndarray, n: int): - return np.concatenate(np.split(a, [n])[::-1]) - - def rotations(a: np.ndarray): + a2 = np.concatenate((a, a)) for i in range(1, len(a)): - yield rotate(a, i) + yield np.split(a2, [i, i + len(a)])[1] def n_body(pos: np.ndarray, vel: np.ndarray, mass: np.ndarray):