Q:

Write a NumPy program to create a Cartesian product of two arrays into single array of 2D points

0

Write a NumPy program to create a Cartesian product of two arrays into single array of 2D points.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([1,2,3])
y = np.array([4,5])
result = np.transpose([np.tile(x, len(y)), np.repeat(y, len(x))])
print(result)

Sample Output:

[[1 4]
 [2 4]
 [3 4]
 [1 5]
 [2 5]
 [3 5]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now