MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / iterate

Function iterate

fractals/koch_snowflake.py:38–50  ·  view source on GitHub ↗

Go through the number of iterations determined by the argument "steps". Be careful with high values (above 5) since the time to calculate increases exponentially. >>> iterate([np.array([0, 0]), np.array([1, 0])], 1) [array([0, 0]), array([0.33333333, 0. ]), array([0.5

(initial_vectors: list[np.ndarray], steps: int)

Source from the content-addressed store, hash-verified

36
37
38def iterate(initial_vectors: list[np.ndarray], steps: int) -> list[np.ndarray]:
39 """
40 Go through the number of iterations determined by the argument "steps".
41 Be careful with high values (above 5) since the time to calculate increases
42 exponentially.
43 >>> iterate([np.array([0, 0]), np.array([1, 0])], 1)
44 [array([0, 0]), array([0.33333333, 0. ]), array([0.5 , \
450.28867513]), array([0.66666667, 0. ]), array([1, 0])]
46 """
47 vectors = initial_vectors
48 for _ in range(steps):
49 vectors = iteration_step(vectors)
50 return vectors
51
52
53def iteration_step(vectors: list[np.ndarray]) -> list[np.ndarray]:

Callers 1

koch_snowflake.pyFile · 0.85

Calls 1

iteration_stepFunction · 0.85

Tested by

no test coverage detected