numpy.insert

numpy.insert(arr, obj, values, axis=None)

Insert values along the given axis before the given indices.

Parameters:

arr : array_like

Input array.

obj : {integer, slice, integer array_like}

Insert values before obj indices.

values : :

Values to insert into arr.

axis : int, optional

Axis along which to insert values. If axis is None then ravel arr first.

Examples

>>> a = np.array([[1,2,3],
...               [4,5,6],
...               [7,8,9]])
>>> np.insert(a, [1,2], [[4],[5]], axis=0)
array([[1, 2, 3],
       [4, 4, 4],
       [4, 5, 6],
       [5, 5, 5],
       [7, 8, 9]])

Previous topic

numpy.delete

Next topic

numpy.resize

This Page

Quick search