[Python] Scipy and Numpy(1)
import numpy as np #Create an array of 1*10^7 elements
arr = np.arange(1e7) #Converting ndarray to list
larr = arr.tolist() #Create a 2D numpy array
arr = np.zeros((3,3)) #Converting a array to matrix
mat = np.matrix(arr)
np.matrix('1,2,3;4,5,6;7,8,9'); #Array Creation
#First we create a list and then
#wrap it with the np.array() function
alist = [1,2,3]
arr = np.array(alist) #Creating an array of zeros with 5 elements
arr = np.zeros(5) #Creating an array going from 0 to 100
#not include 100
arr = np.arange(100) #from 10 to 100 (not include 100)
arr = np.arange(10, 100) #100 steps form 1 to 100
#(start, end, step)
arr = np.linspace(0, 1, 100) #Creating an 5X5 array of zeros
image = np.zeros((5,5)) #Creating a 5X5X5 cube of 1's
#The astype() method sets the array with integer elements
cube = np.zeros(5,5,5).astype(int) + 1 #Or even simpler with 16-bit floating-point precision
cube = np.ones((5,5,5)).astype(np.float16) #Change Data type
#Use dtype: int numpy.float16, numpy.float32, numpy.float64
arr = np.zeros(2, dtype=int)
arr = np.zeros(2, dtype=np.float32) '''
The restructured arrays are just different views
of the same data in memory.
If chang one of them, you will change all.
If you don't want this to happen, then use the numpy.copy function
to separete the arrays mamory-wise.
'''
#Created arrays and reshape them in many others ways
#Creating an array with elements from 0 to 999
arr1d = np.arange(1000) #reshaping the array to a 10x10x10 3D array
arr3d = arr1d.reshape((10,10,10))
arr3d = np.reshape(arr1d, (10,10,10)) #Invesely, we can flatten arrays
arr4d = np.zeros((10,10,10,10))
arr1d = arr4d.ravel()
print arr1d.shape recarr = np.zeros((2,), dtype('i4, f4, a10'))
#the type for the first to third columns
#i4 := 32-bit integer
#f4 := 32-bit float
#a10 := a string 10 characters long #We can assign names to each column
recarr.dtype.names = ('Integers', 'Floats', 'Strings') #Indexing and Slicing
alist = [[1,2],[3,4]]
arr = np.array(alist)
arr[0,1]#It's the same as arr[0][1]
arr[:,1]#return the last column
arr[1,:]#return the bottom row
[Python] Scipy and Numpy(1)的更多相关文章
- python数值计算模块NumPy scipy安装
NumPy为Python提供了快速的多维数组处理的能力,而SciPy则在NumPy基础上添加了众多的科学计算所需的各种工具包,有了这两个库,Python就有几乎和Matlab一样的处理数据和计算的能力 ...
- Python中的Numpy、SciPy、MatPlotLib安装与配置
Python安装完Numpy,SciPy和MatplotLib后,可以成为非常犀利的科研利器.网上关于这三个库的安装都写得非常不错,但是大部分人遇到的问题并不是如何安装,而是安装好后因为配置不当,在使 ...
- 给深度学习入门者的Python快速教程 - numpy和Matplotlib篇
始终无法有效把word排版好的粘贴过来,排版更佳版本请见知乎文章: https://zhuanlan.zhihu.com/p/24309547 实在搞不定博客园的排版,排版更佳的版本在: 给深度学习入 ...
- 使用python scipy.optimize linprog和lingo线性规划求解最大值,最小值(运筹学学习笔记)
1.线性规划模型: 2.使用python scipy.optimize linprog求解模型最优解: 在这里我们用到scipy中的linprog进行求解,linprog的用法见https://doc ...
- python及pandas,numpy等知识点技巧点学习笔记
python和java,.net,php web平台交互最好使用web通信方式,不要使用Jypython,IronPython,这样的好处是能够保持程序模块化,解耦性好 python允许使用'''.. ...
- SciPy和Numpy处理能力
1.SciPy和Numpy的处理能力: numpy的处理能力包括: a powerful N-dimensional array object N维数组: advanced array slicing ...
- Windows下安装Scipy和Numpy失败的解决方案
使用 pip 安装 Scipy 库时,经常会遇到安装失败的问题 pip install numpy pip install scipy 后来网上搜寻了一番才得以解决.scipy 库需要依赖 numpy ...
- Python 机器学习库 NumPy 教程
0 Numpy简单介绍 Numpy是Python的一个科学计算的库,提供了矩阵运算的功能,其一般与Scipy.matplotlib一起使用.其实,list已经提供了类似于矩阵的表示形式,不过numpy ...
- python scipy样条插值函数大全(interpolate里interpld函数)
scipy样条插值 scipy样条插值1.样条插值法是一种以可变样条来作出一条经过一系列点的光滑曲线的数学方法.插值样条是由一些多项式组成的,每一个多项式都是由相邻的两个数据点决定的,这样,任意的两个 ...
随机推荐
- matlab fgetl()
% % file=dir('/home/wang/Desktop/trainset/others/'); % % :length(file) % % path= strcat('/home/wang/ ...
- linux shell终端打开方式
前言 Linux操作系统没有Window操作系统界面友好,使用者需要使用命令与系统进行交互,交互媒介为shell终端. 有三种方式可以打开终端: 方法一: 打开新的窗口并打开shell终端,快捷键:c ...
- L3-018 森森美图 (30 分)
森森最近想让自己的朋友圈熠熠生辉,所以他决定自己写个美化照片的软件,并起名为森森美图.众所周知,在合照中美化自己的面部而不美化合照者的面部是让自己占据朋友圈高点的绝好方法,因此森森美图里当然得有这个功 ...
- CTF-练习平台-Misc之 Telent
三.Telent 下载下来文件,解压压缩包,用记事本打开pcap文件,发现flag
- BZOJ2460,LG4570 [BJWC2011]元素
题意 相传,在远古时期,位于西方大陆的 Magic Land 上,人们已经掌握了用魔法矿石炼制法杖的技术.那时人们就认识到,一个法杖的法力取决于使用的矿石. 一般地,矿石越多则法力越强,但物极必反:有 ...
- ZOJ3545 Rescue the Rabbit
分析 未知定长串中不同已知模板串的出现次数问题,一般做法是AC自动机上dp. 考虑背包,\(dp(i,j,k)\)表示当前串长为\(i\),在AC自动机上对应节点\(j\),已匹配的模板串的状态为\( ...
- LeetCode Single Number I II Python
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- TensorFlow笔记-08-过拟合,正则化,matplotlib 区分红蓝点
TensorFlow笔记-08-过拟合,正则化,matplotlib 区分红蓝点 首先提醒一下,第7讲的最后滑动平均的代码已经更新了,代码要比理论重要 今天是过拟合,和正则化,本篇后面可能或更有兴趣, ...
- 完成分析 FastAdmin 用户余额功能(后台篇)
分析 FastAdmin 用户余额功能(后台篇) 分析 FastAdmin 用户余额功能(后台篇) 虽然 FastAdmin 主要针对后台的框架,但也在不断完善前台的功能,有一天小伙伴在社区里提了一个 ...
- 【转】每天一个linux命令(24):Linux文件类型与扩展名
原文网址:http://www.cnblogs.com/peida/archive/2012/11/22/2781912.html Linux文件类型和Linux文件的文件名所代表的意义是两个不同的概 ...