insert a new row to numpy array in especific position

Solutions on MaxInterview for insert a new row to numpy array in especific position by the best coders in the world

showing results for - "insert a new row to numpy array in especific position"
Lia
05 Jun 2016
1>>> import numpy as np
2>>> a = np.zeros((2, 2))
3>>> a
4array([[ 0.,  0.],
5       [ 0.,  0.]])
6# In the following line 1 is the index before which to insert, 0 is the axis.
7>>> np.insert(a, 1, np.array((1, 1)), 0)  
8array([[ 0.,  0.],
9       [ 1.,  1.],
10       [ 0.,  0.]])
11>>> np.insert(a, 1, np.array((1, 1)), 1)
12array([[ 0.,  1.,  0.],
13       [ 0.,  1.,  0.]])