Python NumPy: Convert two 1-D arrays into a 2-D array
Python NumPy: Array Object Exercise-60 with Solution
Write a Python program to convert (in sequence depth wise (along third axis)) two 1-D arrays into a 2-D array.
Sample array: (10,20,30), (40,50,60)
import numpy as np a = np.array([,,]) b = np.array([,,]) c = np.dstack((a, b)) print(c)
[[[10 40]] [[20 50]] [[30 60]]]
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to convert 1-D arrays as columns into a 2-D array.
Next: Write a Python program to split an array of 14 elements into 3 arrays, each of which has 2, 4, and 8 elements in the original order.
What is the difficulty level of this exercise?