Python NumPy: Insert a new axis within a 2-D array
Python NumPy: Array Object Exercise-56 with Solution
Write a Python program to insert a new axis within a 2-D array.
2-D array of shape (3, 4).
New shape will be will be (3, 1, 4).
import numpy as np x = np.zeros((3, 4)) y = np.expand_dims(x, axis=1).shape print(y)
(3, 1, 4)
Python Code Editor:
Improve this sample solution and post your code through Disqus