PyScript Testing¶
2
1
print("Hello World!")
2
Activity: 1 ActiveCode (ac_example1)
20
1
import numpy as np
2
3
# Creating a numpy array
4
arr = np.array([1, 2, 3, 4, 5])
5
6
# Performing operations
7
arr_squared = arr ** 2 # Squaring each element
8
9
# Generating a range of numbers
10
range_arr = np.arange(10) # 0 to 9
11
12
# Reshaping an array
13
reshaped_arr = range_arr.reshape(2, 5) # Reshape to 2 rows, 5 columns
14
15
# Display results
16
print("Original array:", arr)
17
print("Squared array:", arr_squared)
18
print("Range array:", range_arr)
19
print("Reshaped array (2x5):", reshaped_arr)
20
Activity: 2 ActiveCode (ac_example2)
36
1
import matplotlib.pyplot as plt
2
import matplotlib.tri as tri
3
import numpy as np
4
5
from pyscript import display
6
7
# First create the x and y coordinates of the points.
8
n_angles = 36
9
n_radii = 8
10
min_radius = 0.25
11
radii = np.linspace(min_radius, 0.95, n_radii)
12
13
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
14
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
15
angles[:, 1::2] += np.pi / n_angles
16
17
x = (radii * np.cos(angles)).flatten()
18
y = (radii * np.sin(angles)).flatten()
19
z = (np.cos(radii) * np.cos(3 * angles)).flatten()
20
21
# Create the Triangulation; no triangles so Delaunay triangulation created.
22
triang = tri.Triangulation(x, y)
23
24
# Mask off unwanted triangles.
Activity: 3 ActiveCode (ac_example3)
You have attempted 1 of 4 activities on this page