- #1

bolzano95

- 89

- 7

- TL;DR Summary
- I'm trying to program a Sierpinski triangle for n-iterations.

Hi,

I'm new to programming in python [total beginner in programming] and I would like to ask you for your help.

Here is what I got so far:

I want to get three points for each random integer first and then bring them out of the loop (save them):

t1

t2

t3

For the 2.iteration I want to continue the for loop for each of t1, t2, t3 (I get aditional 9 points).

3. iteration ---> additional 27 points and so on ...

What would be the syntax for this?

Also, how to export new points into a data file?

What about plotting all the points?

Is there a 'grid' for these arrays? I read about numpy.zeros(), but it was explained this is a function for matrixes, so I'm not sure how to implement this into the program.

Any help or tips will be much appreciated.

I'm new to programming in python [total beginner in programming] and I would like to ask you for your help.

Here is what I got so far:

Python:

```
import numpy as np
import random
from math import sqrt
p = np.array([(0, 0), (1, 0), (1, (1/sqrt(2)))], dtype=float)
t = np.array((0, 0), dtype=float)
for i in range(1): # That's the 1.iteration
r = random.randint(0, 2) #
t = (p[r] + t)/2
```

I want to get three points for each random integer first and then bring them out of the loop (save them):

t1

t2

t3

For the 2.iteration I want to continue the for loop for each of t1, t2, t3 (I get aditional 9 points).

3. iteration ---> additional 27 points and so on ...

What would be the syntax for this?

Also, how to export new points into a data file?

What about plotting all the points?

Is there a 'grid' for these arrays? I read about numpy.zeros(), but it was explained this is a function for matrixes, so I'm not sure how to implement this into the program.

Any help or tips will be much appreciated.