The delete()
function in Python is used to delete the sub-arrays of a given array along a specified axis.
The delete()
function takes the syntax below:
numpy.delete(arr, obj, axis=None)
The delete()
function takes the following parameter values:
arr
: This is the input array. It is a required parameter.obj
: This specifies the index number or position of the sub-array of a
to be deleted. It is a required parameter.axis
: This is the axis along which the sub-array of the input array is to be deleted. It is an optional parameter.The delete()
function returns a copy of the input array, a
, except that the elements specified by obj
are removed.
import numpy as np# creating an input arraya = np.array([[1,2,3], [4,5,6], [7,8,9]])# calling the tile() functionmy_array = np.delete(a, 1, axis=0)# printing the input array and the new arrayprint(a)print(my_array)
numpy
module.a
, using the array()
function.delete()
function on the input array. The result is assigned to a variable, my_array
.my_array
.