-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
64 lines (50 loc) · 1.49 KB
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Creates matrix of coords based on the size of both inputs.
# For ex the 1st input of meshgrid() above is 1 x 6 and the 2nd is 1 x 4
# which means we are making a grid of 6 xcoords and 4 ycoords
np.meshgrid(np.arange(1, 13, 2), np.arange(-15, -3, 3))
[array([[ 1, 3, 5, 7, 9, 11],
[ 1, 3, 5, 7, 9, 11],
[ 1, 3, 5, 7, 9, 11],
[ 1, 3, 5, 7, 9, 11]]),
array([[-15, -15, -15, -15, -15, -15],
[-12, -12, -12, -12, -12, -12],
[ -9, -9, -9, -9, -9, -9],
[ -6, -6, -6, -6, -6, -6]])]
x.ravel()
array([ 1, 3, 5, 7, 9, 11, 1, 3, 5, 7, 9, 11, 1, 3, 5, 7, 9,
11, 1, 3, 5, 7, 9, 11])
# Create Individual Tuples for each point in an array
coords = [(a, b) for a, b in zip(x.ravel(), y.ravel())]
XYpairs = np.dstack([XX, YY]).reshape(-1, 2)`
np.vstack([XX.ravel(), YY.ravel()]).T
# For 3D points
data = np.concatenate((x[:, np.newaxis], y[:, np.newaxis], z[:, np.newaxis]),
axis=1)
[(1, -15),
(3, -15),
(5, -15),
(7, -15),
(9, -15),
(11, -15),
(1, -12),
(3, -12),
(5, -12),
(7, -12),
(9, -12),
(11, -12),
(1, -9),
(3, -9),
(5, -9),
(7, -9),
(9, -9),
(11, -9),
(1, -6),
(3, -6),
(5, -6),
(7, -6),
(9, -6),
(11, -6)]
# To get array for each axis
XYpairs = np.vstack([ x.reshape(-1), y.reshape(-1) ])[0]
array([ 1, 3, 5, 7, 9, 11, 1, 3, 5, 7, 9, 11, 1, 3, 5, 7, 9,
11, 1, 3, 5, 7, 9, 11])