Answers for "insert a new row to numpy array in especific position"

0

insert a new row to numpy array in especific position

>>> import numpy as np
>>> a = np.zeros((2, 2))
>>> a
array([[ 0.,  0.],
       [ 0.,  0.]])
# In the following line 1 is the index before which to insert, 0 is the axis.
>>> np.insert(a, 1, np.array((1, 1)), 0)  
array([[ 0.,  0.],
       [ 1.,  1.],
       [ 0.,  0.]])
>>> np.insert(a, 1, np.array((1, 1)), 1)
array([[ 0.,  1.,  0.],
       [ 0.,  1.,  0.]])
Posted by: Guest on May-12-2020

Code answers related to "insert a new row to numpy array in especific position"

Python Answers by Framework

Browse Popular Code Answers by Language