Q:

Write a NumPy program to build an array of all combinations of three NumPy arrays

0

Write a NumPy program to build an array of all combinations of three NumPy arrays.

All Answers

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

import numpy as np
x = [1, 2, 3]
y = [4, 5]
z = [6, 7]
print("Original arrays:")
print("Array-1")
print(x)
print("Array-2")
print(y)
print("Array-3")
print(z)
new_array = np.array(np.meshgrid(x, y, z)).T.reshape(-1,3)
print("Combine array:")
print(new_array)
Sample Output:
Original arrays:
Array-1
[1, 2, 3]
Array-2
[4, 5]
Array-3
[6, 7]
Combine array:
[[1 4 6]
 [1 5 6]
 [2 4 6]
 [2 5 6]
 [3 4 6]
 [3 5 6]
 [1 4 7]
 [1 5 7]
 [2 4 7]
 [2 5 7]
 [3 4 7]
 [3 5 7]]

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