Skip to content

Commit 115772a

Browse files
use np to solve equation
1 parent e014950 commit 115772a

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

31.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
from PIL import Image
22
from PIL import ImageSequence
3+
import numpy as np
4+
import matplotlib.pyplot as plt
35

46

57
def main():
68
pic_path = "ufo/mandelbrot.gif"
7-
first_step(pic_path)
9+
# first_step(pic_path)
10+
# second_step()
11+
# plt.imshow(mandelbrot(1000, 1000))
12+
# plt.show()
13+
numPyVersion()
814

915

1016
def first_step(input):
@@ -18,9 +24,44 @@ def first_step(input):
1824
height = 480
1925
for x in range(width):
2026
for y in range(height):
21-
print(im.getpixel((x, y)), end = " ")
27+
print(im.getpixel((x, y)), end=" ")
2228
print()
2329

2430

31+
def second_step():
32+
a = np.arange(15).reshape(3, 5)
33+
print(a)
34+
print(a.shape)
35+
print(a.ndim)
36+
print(a.dtype.name)
37+
print(a.dtype)
38+
print(a.itemsize)
39+
print(type(a))
40+
41+
b = np.array([6, 7, 8])
42+
print(b)
43+
print(b.shape)
44+
pass
45+
46+
47+
def mandelbrot(h, w, maxit=20):
48+
y, x = np.ogrid[-1.4:1.4:h * 1j, -2:0.8:w * 1j]
49+
c = x + y * 1j
50+
z = c
51+
divtime = maxit + np.zeros(z.shape, dtype=int)
52+
53+
for i in range(maxit):
54+
z = z ** 2 + c
55+
diverge = z * np.conj(z) > 2 ** 2
56+
div_now = diverge & (divtime == maxit)
57+
divtime[div_now] = i
58+
z[diverge] = 2
59+
return divtime
60+
61+
62+
def numPyVersion():
63+
print(np.version.version)
64+
65+
2566
if __name__ == "__main__":
2667
main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy