np.diff函数

觉得有用的话,欢迎一起讨论相互学习~Follow Me

数组中a[n]-a[n-1]

import numpy as np
a=np.array([1, 6, 7, 8, 12])
diff_x1 = np.diff(a)
print("diff_x1",diff_x1)
# diff_x1 [5 1 1 4]
# [6-1,7-6,8-7,12-8]

高维数组同样适用

二维数组

b=np.array([[1, 6, 7, 8, 12],[1, 6, 7, 8, 12]])
diff_x2 = np.diff(b)
print("diff_x2 \n",diff_x2)
# diff_x2
# [[5 1 1 4]
# [5 1 1 4]]

高维数组

c=b.reshape(5,1,2)
diff_x3 = np.diff(c)
print("diff_x3 \n",diff_x3)
# diff_x3
# [[[ 5]] [6-1]
#
# [[ 1]] [8-7]
#
# [[-11]] [1-12]
#
# [[ 1]] [7-6]
#
# [[ 4]]] [12-8]

np.diff函数的更多相关文章

  1. np.argsort函数

    np.argsort函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me numpy.argsort(a, axis=-1, kind='quicksort', order=None) 功能: ...

  2. SAS笔记(3) LAG和DIFF函数

    在实际的应用中,我们会想查看当前观测的上一个观测值,在上一篇博客中我们使用了RETAIN语句来记录上一条观测,其实SAS还提供了一个很好用的函数LAG.当我们使用函数时,一定要明确该函数的返回值是什么 ...

  3. pandas dataframe 时间字段 diff 函数

    pandas pandas 是数据处理的利器,非常方便进行表格数据处理,用过的人应该都很清楚,没接触的可以自行查阅pandas 官网. 需求介绍 最近在使用 pandas 的过程中碰到一个问题,需要计 ...

  4. 理解np.nonzero()函数

    举三个例子,就能清楚的看到 np.nonzero() 这个函数返回值的意义 一. #例1 一维数组 import numpy as np a = [0,1,2,0,3,0] b = np.nonzer ...

  5. diff函数的实现——LCS的变种问题

    昨天去去哪儿笔试,碰到了一个我们一直很熟悉的命令(diff——ubuntu下面),可以比较字符串,即根据最长公共子串问题,如果A中有B中没有的字符输出形式如下(-ch),如果A中没有,B中有可以输出如 ...

  6. diff函数(matlab)

    diff函数式用于求导数和差分的.无论是求导数还是差分,其原理是一样的. 这里简单介绍下其用法: 前后相邻元素之差 上下相邻行之差. 与diff(A,1,1)类似. 第三个参数为2时,则变为列差分运算 ...

  7. Py之np.concatenate函数【转载】

    转自:https://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html 1.nupmy.concatenate函数 ...

  8. np.repeat函数

    np.repeat用法 觉得有用的话,欢迎一起讨论相互学习~Follow Me np.repeat用于将numpy数组重复 一维数组重复三次 import numpy as np # 随机生成[0,5 ...

  9. diff()函数的使用

    1.diff():返回略微迭代(lagged)的或滞后的不同(iterated diferences). > x<-cumsum(cumsum(1:10)) > x [1] 1 4 ...

随机推荐

  1. QQ测试计划

             

  2. mvc 页面方法学习-RenderBody方法

    教程地址:https://docs.microsoft.com/zh-cn/aspnet/mvc/overview/getting-started/introduction/adding-a-view

  3. 更新ubuntu的源

    什么是Ubuntu的软件源? 我们在使用Debian或者Ubuntu的apt-get工具来安装需要的软件时,其实就是从服务器获取需要安装的软件并把它安装在本地计算机的过程.所谓的软件源,就是我们获取软 ...

  4. Internet History, Technology and Security (Week 9)

    Week 9 Security: Web Security We are now on the second to last week of the class and finishing up ou ...

  5. [转帖]高通推出八核笔电处理器骁龙8cx 能超英特尔吗?

    高通推出八核笔电处理器骁龙8cx 能超英特尔吗? https://baijiahao.baidu.com/s?id=1619154699684981202&wfr=spider&for ...

  6. [转帖]Beyond Compare如何进行二进制比较

    Beyond Compare如何进行二进制比较 http://www.beyondcompare.cc/jiqiao/erjinzhi-bijiao.html 在使用Beyond Compare软件比 ...

  7. [转帖]IBM POWER9 E950 and E980 Servers Launched

    IBM POWER9 E950 and E980 Servers Launched https://www.servethehome.com/ibm-power9-e950-and-e980-serv ...

  8. 微信小程序 功能函数 密码验证*

    //登录输入密码 userPasswordInput: function (e) { var that = this; this.setData({ userPassword: e.detail.va ...

  9. robotium学习及整理

    一.                      Robotium 简介 Robotium是一款国外的Android自动化测试框架,主要针对Android平台的应用进行黑盒自动化测试,它提供了模拟各种手 ...

  10. Youtube API数据类型

    数据类型 Activitys Activity资源包含了特定频道或用户的所有活动信息,包括打分.分享.喜爱.上传视频等等.每个Activity资源标识出了动作类型.频道或其他资源. Captions ...