numpy及scipy的使用
numpy的使用
把list A转换为numpy 矩阵
np.array(A)
np.array(A, 'int32')
numpy加载txt文件里面的矩阵
matrix = np.loadtxt(txt_name, dtype='i', delimiter=',')
将nparray里面每个元素转换为int型
nparray.astype(int)
array[::2] 的用法
array.shape = (2*n,)
array.shape[::2] #表示第奇数个元素组成的向量
array.shape[1::2] #表示第偶数个元素组成的向量
numpy删除固定行,或者固定列元素
det.shape => (4,5)
np.delete(det, (row_idx), axis=0) #axis=0表示删除行,axis=1表示删除列
det.shape => (3,5)
维度扩展
np.expand_dims(array, axis=0) #将(96,96) 扩展成为(1,96,96)
通道转换——transpose
array.shape = (batchsize, w, h ,channels)
array_new=np.transpose(array, (0,3,1,2))
numpy array与常数比较大小
array > threshold #将得到一个array, 它的size与原始array相同,元素由0,1构成
求和
np.sum(array) #将array中所有元素相加
连接
np.concatenate
list = range(0,100)
np.concatenate((t[:3], t[10:]), axis=0)
numpy.clip(a, a_min, a_max, out=None) #过滤大于或小于某个区间的值
exm = np.array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]])
np.clip(exm, 3, 11)
output:
array([[ 3, 3, 3, 3, 4, 5, 6, 7, 8, 9],
[ 5, 6, 7, 8, 9, 10, 11, 11, 11, 11]]) #将小于区间值设置为区间低值,大于的设置为区间高值
scipy的使用
ndimage.zoom
array.shape = batchsize, channels, w, h
array_new = scipy.ndimage.zoom(array, (1,1,resizescale, resizescale))
numpy及scipy的使用的更多相关文章
- python安装numpy、scipy和matplotlib等whl包的方法
最近装了python和PyCharm开发环境,但是在安装numpy和matplotlib等包时出现了问题,现总结一下在windows平台下的安装方法. 由于现在找不到了工具包新版本的exe文件,所以采 ...
- centos 7 下安装numpy、scipy等python包
本文适用于刚入门的小白,欢迎大牛们批评指正. 因为要开始数据分析,而python又不像R和matlab那么简洁.需要安装的包很多~ 网上找了好多牛人博客,想在centos7下安装numpy,scipy ...
- Python下科学计算包numpy和SciPy的安装
转载自:http://blog.sina.com.cn/s/blog_62dfdc740101aoo6.html Python下大多数工具包的安装都很简单,只需要执行 “python setup.py ...
- Python 学习之中的一个:在Mac OS X下基于Sublime Text搭建开发平台包括numpy,scipy
1 前言 Python有许多IDE能够用,官方自己也带了一个,Eclipse也能够. 但我在使用各种IDE之后,发现用Sublime Text是最好用的一个.因此.我都是用Sublime Text来编 ...
- [笔记]我的Linux入门之路 - 05.Eclipse的Python开发环境搭建与Numpy、Scipy库安装
一.Python环境 直接终端查询下python安装没:python --version Python 2.7.12 Ubuntu竟然已经装了Python2.7,那就好说了.不然自己装和装jdk差不多 ...
- centos6.5安装python2.7、pip、numpy、scipy
1..安装Development Tools yum groupinstall -y 'development tools' 2.安装SSL.bz2.zlib来为Python的安装做好准备工作 yum ...
- Numpy、SciPy、MatPlotLib在Python2.7.9下的安装与配置
前言: Python安装完Numpy,SciPy和MatplotLib后,可以成为非常犀利的科研利器.网上关于这三个库的安装都写得非常不错,但是大部分人遇到的问题并不是如何安装,而是安装好后因为配置不 ...
- 有关python numpy pandas scipy 等 能在YARN集群上 运行PySpark
有关这个问题,似乎这个在某些时候,用python写好,且spark没有响应的算法支持, 能否能在YARN集群上 运行PySpark方式, 将python分析程序提交上去? Spark Applicat ...
- numpy、scipy、matplotlib、OpenCV安装及问题解决
1 numpy 概述 numpy是Numerical Python的缩写,释义为数值的Python numpy弥补了作为通用编程语言的Python在数值计算方面能力弱.速度慢的不足(numpy的底层是 ...
- python安装pip、numpy、scipy、statsmodels、pandas、matplotlib等
1.安装python 2.安装numpy(开源的数值计算扩展,可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结构要高效的多. 很多库都是以此库为依 ...
随机推荐
- CCPC-Winter Camp div2 day5
DIV2 有部分div1的题会写 div1的大佬真的太强了 向他们学习 (好像和zqc大佬说过话了hhh,zqc大佬真的是一个超有意思的人啊,羡慕有妹子队友的zqc大佬) A: 你有一棵树,你想把它画 ...
- HDU 4529 状压dp
郑厂长系列故事——N骑士问题 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- HDU3376 最小费用最大流 模板2
Matrix Again Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)To ...
- Centos7 安装rabbitmq(转载)
原文地址:http://blog.csdn.net/wenyu826/article/details/71108279 安装Erlang 从链接https://packages.erlang-solu ...
- spring事务的一些注意点
参考文章 http://blog.csdn.net/qq_34021712/article/details/75949779 ©王赛超 1.在需要事务管理的地方加@Transactional 注解 ...
- gitlab通过api创建组、项目、成员
前戏 获取gitlab中admin用户的private_token Groups API 获取某个组的详细 curl --header "PRIVATE-TOKEN: *********&q ...
- JNLP Slave connection error解决办法
Replace in jnlp-file <argument>-workDir</argument> <argument /> with <argume ...
- 【BZOJ3769】BST again [DP]
BST again Time Limit: 10 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 求有多少棵大小为n的深度 ...
- Warning: File upload error - unable to create a temporary file in Unknown on line 0
upload_tmp_dir 临时文件夹问题 上传文件提示 Warning: File upload error - unable to create a temporary file in Unkn ...
- input file 文件上传,js控制上传文件的大小和格式
文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...