首页 > 其他分享 >无涯教程-NumPy - delete函数

无涯教程-NumPy - delete函数

时间:2023-10-17 13:31:53浏览次数:44  
标签:无涯 np 数组 print array axis NumPy delete

此函数返回一个新数组,其中指定的子数组已从数组中删除,与insert()函数一样,如果不使用axis参数,则将输入数组展平,该函数采用以下参数-

Numpy.delete(arr, obj, axis)
Sr.No. Parameter & 描述
1

arr

输入数组

2

obj

可以是切片,整数或整数数组,指示要从输入数组中删除的子数组

3

axis

删除给定子数组所沿的轴。如果未给出,则将arr展平

import numpy as np 
a = np.arange(12).reshape(3,4) 

print 'First array:' 
print a 
print '\n'  

print 'Array flattened before delete operation as axis not used:' 
print np.delete(a,5) 
print '\n'  

print 'Column 2 deleted:'  
print np.delete(a,1,axis = 1) 
print '\n'  

print 'A slice containing alternate values from array deleted:' 
a = np.array([1,2,3,4,5,6,7,8,9,10]) 
print np.delete(a, np.s_[::2])

其输出如下-

First array:
[[ 0 1 2 3]
 [ 4 5 6 7]
 [ 8 9 10 11]]

Array flattened before delete operation as axis not used:
[ 0 1 2 3 4 6 7 8 9 10 11]

Column 2 deleted:
[[ 0 2 3]
 [ 4 6 7]
 [ 8 10 11]]

A slice containing alternate values from array deleted:
[ 2 4 6 8 10]

参考链接

https://www.learnfk.com/numpy/numpy-delete.html

标签:无涯,np,数组,print,array,axis,NumPy,delete
From: https://blog.51cto.com/u_14033984/7903045

相关文章

  • 无涯教程-NumPy - resize函数
    此函数返回具有指定大小的新数组,该函数采用以下参数。numpy.resize(arr,shape)Sr.No.描述1arr输入数组要调整大小2shape输出数组的新维度importnumpyasnpa=np.array([[1,2,3],[4,5,6]])print'Firstarray:'printaprint'\n'print'Theshapeo......
  • 无涯教程-NumPy - broadcast_to函数
    此功能将数组广播为新维度,它返回原始数组的只读视图,如果新维度不符合NumPy的广播规则,则该函数可能会引发ValueError。注意-此功能自版本1.10.0起可用。该函数采用以下参数。numpy.broadcast_to(array,shape,subok)importnumpyasnpa=np.arange(4).reshape(1,4)prin......
  • 无涯教程-NumPy - swapaxes函数
    此函数互换数组的两个轴,对于1.10之后的NumPy版本,将返回交换数组的视图,该函数采用以下参数。numpy.swapaxes(arr,axis1,axis2)Sr.No.Parameter&描述1arr要交换其轴的输入数组2axis1与第一个轴对应的int3axis2与第二个轴对应的int#Itcreatesa3dimen......
  • 无涯教程-NumPy - rollaxis函数
    此功能使指定的轴向后滚动,直到它位于指定的位置,该函数具有三个参数。numpy.rollaxis(arr,axis,start)Sr.No.Parameter&描述1arr输入数组2axis轴向后滚动。其他轴的位置相对彼此不变3start默认情况下为零,以完成整个滚动。滚动直到到达指定位置#Itcreate......
  • numpy基础
    In [1]:pipinstallnumpy  Requirementalreadysatisfied:numpyinc:\users\dengzl\.conda\envs\data_analysis\lib\site-packages(1.26.0)Note:youmayneedtorestartthekerneltouseupdatedpackages. In [2]:#创建一个......
  • 创建numpy数组
     1.2.1创建NumPy数组的多种方式¶array:将数组转换为ndarray,推断dtype或者显示指定arange:类似内置函数range,返回ndarrayzeros:创建全0数组,可指定形状和dtypeones:创建全1数组,可指定形状和dtypeempty:创建新数组,只分配内存空间、不填充任何值1.2.2转换NumPy数......
  • numpy基本操作
      1.3.1索引¶单个元素索引:一维数组、负数索引二维数组的索引1.3.2切片¶切片跨步索引数组:针对多为数组的索引索引结合切片 In [1]:importnumpyasnp In [2]:#一维数组索引array1=np.array([1,2,3,4,5])array......
  • Numpy数据运算
    1.4-NumPy数组运算  1.4.1算术运算¶add加subtract减multipie乘divide除1.4.2数学运算¶三角函数:sin,cos,tan算术运算1.4.3统计运算¶mean均值average均值var方差std标准差1.4.4聚合运算¶性能区别:np聚合函数和py内置函数sum......
  • 无涯教程-NumPy - reshape函数
    此函数在不更改数据的情况下为数组提供了新的维度,它接受以下参数-numpy.reshape(arr,newshape,order')Sr.No.描述1arr数组2newshapeint或int的元组,新维度应与原始维度兼容3order如果数组存储在类似Fortran的连续内存中,则"C"表示C风格,"F"表示Fortran风格,"......
  • 无涯教程-NumPy - Matplotlib
    Matplotlib是Python的绘图库,它与NumPy一起使用,提供了一个环境,是MatLab的有效开源替代方案,它可以与PyQt和wxPython等图形工具包一起使用Matplotlib模块最初由JohnD.Hunter编写。自2012年以来,MichaelDroettboom是主要开发人员。目前,Matplotlib版本。1.5.1是可用的稳定版本。......