解决问题:

有一个固定长度的1维矩阵,将这个矩阵的取样点进行扩充和减少

功能函数:

 def discrete_scale(data, num):
import numpy as np
import copy
"""
:param data: 原始一维矩阵数据
:param num: 设定的样本长度
:return d1: 目标矩阵输出
"""
len = data.shape[0] # 原始数据长度 if len < num: # 样本扩展
t = (len - 1) / (num - 1) # 映射差值
d0 = np.array(range(num)) # 序列映射
d0 = d0 * t d0_1 = copy.deepcopy(d0).astype(int) # 整数部分
d0_0 = d0 - d0_1 # 小数部分
dist = data[1:] - data[:-1] # 维度减小一个数据
d1_1 = data[d0_1]
d1_0 = dist[d0_1[:-1]]
d1_0 = d1_0 * d0_0[:-1]
d1 = copy.deepcopy(d1_1[:-1] + d1_0)
d1 = np.hstack((d1, data[-1])) elif len > num: # 样本压缩
t = (len - 1) / num # 映射差值 分成7个给值区域
d0 = np.array(range(num + 1)) # 序列映射
d0 = d0 * t d0_1 = copy.deepcopy(d0).astype(int) # 整数部分
list = []
for i in range(d0_1.shape[0] - 1):
list.append(np.mean(data[d0_1[i]:d0_1[i + 1] + 1]))
d1 = np.array(list) else: # 目标长度与原始长度相同
d1 = data
return d1

实例程序:

 import numpy as np
a = np.array(range(0,1000))
print(a)
b = np.sin(a/100)
print(b) num = 100
x1 = np.array(range(num))
y1 = discrete_scale(b, num) import matplotlib.pylab as plt
plt.plot(x1, y1, 'r-')
plt.plot(a, b, 'b-')
plt.show()
print(b)

python 离散序列 样本数伸缩(原创)的更多相关文章

  1. 第二天:python的函 数、循环和条件、类

    https://uqer.io/community/share/54c8af17f9f06c276f651a54 第一天学习了Python的基本操作,以及几种主要的容器类型,今天学习python的函数 ...

  2. 关于VisualStudio性能分析数据中的独占样本数和非独占样本数的意义

    VisualStudio中自带有Profile工具进行性能性能分析,其中用得比较多的数据是函数调用时间,它主要有独占样本数和非独占样本数两个指标,关于这两个指标代表的意义,MSDN的解释比较文艺: 非 ...

  3. Python学习day15-函数进阶(3)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  4. Python学习day14-函数进阶(2)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  5. Python学习day13-函数进阶(1)

    Python学习day13-函数进阶(1) 闭包函数 闭包函数,从名字理解,闭即是关闭,也就是说把一个函数整个包起来.正规点说就是指函数内部的函数对外部作用域而非全局作用域的引用. 为函数传参的方式有 ...

  6. Python学习day12-函数基础(2)

    <!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...

  7. Python学习day11-函数基础(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  8. python 特定份数的数据概率统计(原创)

    使用numpy模块中的histogram函数模块 Histogram(a,bins=10,range=None,normed=False,weights=None)其中, a是保存待统计数据的数组, ...

  9. Python 文件行数读取的三种方法

    Python三种文件行数读取的方法: #文件比较小 count = len(open(r"d:\lines_test.txt",'rU').readlines()) print c ...

随机推荐

  1. mysql数据库字段内容替换

    UPDATE 表名 SET 字段名= replace(字段名, '查找内容', '替换成内容') ; UPDATE car_articles SET article_title = replace(a ...

  2. MySQL 详细学习笔记

    Windows服务 -- 启动MySQL net start mysql -- 创建Windows服务 sc create mysql binPath= mysqld_bin_path(注意:等号与值 ...

  3. 通过启动函数定位main()函数

      如下,通过vc6.0编写一个hello world程序.尝试结合汇编代码.分析启动函数找到main函数.   在printf(xxx)插入断点,调试执行.如下,在堆栈窗口中可见main()下的一个 ...

  4. swift 警告框 - 自定义按钮颜色,图片

    1.封装 弹框http://www.hangge.com/blog/cache/detail_651.html import UIKit extension UIAlertController { / ...

  5. js 面向对象的三大特性

    一.封装 所谓封装的概念,是不希望暴露函数中属性或者方法的地址,使外界不能操作,但是可以暴露特有的公有接口,可以利用接口操作. function hello(){ var name='xiaoming ...

  6. 微擎开发------day03

    微擎系统的路由 首先附上一张完整的项目目录图,可下载图片后查看详情 详细的路由介绍 (1)后台系统路由 例如:http://local.drp.com/web/index.php?c=home& ...

  7. (转载)Ubuntu 安装GNU Scientific library(GSL)

    背景: Blei的hlda的C语言实现需要使用C语言的科学计算包GSL,因此决定安装.由于在windows下安装极其繁琐,先在Linux上安装之. 系统环境: Linux version 2.6.35 ...

  8. 【.Net】 大文件可使用的文本分组统计工具(附带源码,原创)

    本工具可实现的效果: 1.读取大文件(大于1GB) 2.根据分隔符分割后的列分组 3.速度快. 4.处理过程中,可以随时停止处理,操作不卡死. 5.有对当前内存的实时监测,避免过多占用内存,影响系统运 ...

  9. rpc和http

    rpc,远程过程调用,分布式各服务在不同的节点,因为不在同一进程中,所以节点间的调用需要通过网络进行传输,rpc是基于tcp/ip的,通过长连接进行通信.客户端需要缓存服务端的ip和端口,服务端也要缓 ...

  10. font-smoothing使用后字体看起来会更清晰舒服

    CSS3里面加入了一个“-webkit-font-smoothing”属性. 这个属性可以使页面上的字体抗锯齿,使用后字体看起来会更清晰舒服. 加上之后就顿时感觉页面小清晰了. 淘宝也在用哦! 它有三 ...