대학원 공부/programming language

Numpy : from itertools import product

월곡동로봇팔 2020. 6. 4. 16:24

from itertools import product

from itertools import product

X = np.array([[1.50,2],[1.60,2],[1.70,2], [1.80,2], [2.00,2], [2.20, 2], [2.50,2], [2.80,2],[3.00,2], [3.30,2], [3.60,2], [5.00,2], 
              [1.50,1],[1.60,1],[1.70,1], [1.80,1], [2.00,1], [2.20, 1], [2.50,1], [2.80,1],[3.00,1], [3.30,1], [3.60,1], [5.00,1],
              [1.50,3],[1.60,3],[1.70,3], [1.80,3], [2.00,3], [2.20, 3], [2.50,3], [2.80,3],[3.00,3], [3.30,3], [3.60,3], [5.00,3],
              [1.50,4],[1.60,4],[1.70,4], [1.80,4], [2.00,4], [2.20, 4], [2.50,4], [2.80,4],[3.00,4], [3.30,4], [3.60,4], [5.00,4],])

# Input space
x1 = np.linspace(X[:,0].min(), X[:,0].max()) #p
print(x1)
"""
[1.5        1.57142857 1.64285714 1.71428571 1.78571429 1.85714286
 1.92857143 2.         2.07142857 2.14285714 2.21428571 2.28571429
 2.35714286 2.42857143 2.5        2.57142857 2.64285714 2.71428571
 2.78571429 2.85714286 2.92857143 3.         3.07142857 3.14285714
 3.21428571 3.28571429 3.35714286 3.42857143 3.5        3.57142857
 3.64285714 3.71428571 3.78571429 3.85714286 3.92857143 4.
 4.07142857 4.14285714 4.21428571 4.28571429 4.35714286 4.42857143
 4.5        4.57142857 4.64285714 4.71428571 4.78571429 4.85714286
 4.92857143 5.        ]
"""
x2 = np.linspace(X[:,1].min(), X[:,1].max()) #q
x = (np.array([x1, x2])).T

x1x2 = np.array(list(product(x1, x2)))

print(x1x2)
[1.5 1. ]
[1.5        1.06122449]
[1.5        1.12244898]
[1.5        1.18367347]
[1.5        1.24489796]
[1.5        1.30612245]
..............
[1.5 4. ]
[1.57142857 1.        ]
[1.57142857 1.06122449]
[1.57142857 1.12244898]
[1.57142857 1.18367347]
[1.57142857 1.24489796]
[1.57142857 1.30612245]
..............