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)的更多相关文章

  1. python数值计算模块NumPy scipy安装

    NumPy为Python提供了快速的多维数组处理的能力,而SciPy则在NumPy基础上添加了众多的科学计算所需的各种工具包,有了这两个库,Python就有几乎和Matlab一样的处理数据和计算的能力 ...

  2. Python中的Numpy、SciPy、MatPlotLib安装与配置

    Python安装完Numpy,SciPy和MatplotLib后,可以成为非常犀利的科研利器.网上关于这三个库的安装都写得非常不错,但是大部分人遇到的问题并不是如何安装,而是安装好后因为配置不当,在使 ...

  3. 给深度学习入门者的Python快速教程 - numpy和Matplotlib篇

    始终无法有效把word排版好的粘贴过来,排版更佳版本请见知乎文章: https://zhuanlan.zhihu.com/p/24309547 实在搞不定博客园的排版,排版更佳的版本在: 给深度学习入 ...

  4. 使用python scipy.optimize linprog和lingo线性规划求解最大值,最小值(运筹学学习笔记)

    1.线性规划模型: 2.使用python scipy.optimize linprog求解模型最优解: 在这里我们用到scipy中的linprog进行求解,linprog的用法见https://doc ...

  5. python及pandas,numpy等知识点技巧点学习笔记

    python和java,.net,php web平台交互最好使用web通信方式,不要使用Jypython,IronPython,这样的好处是能够保持程序模块化,解耦性好 python允许使用'''.. ...

  6. SciPy和Numpy处理能力

    1.SciPy和Numpy的处理能力: numpy的处理能力包括: a powerful N-dimensional array object N维数组: advanced array slicing ...

  7. Windows下安装Scipy和Numpy失败的解决方案

    使用 pip 安装 Scipy 库时,经常会遇到安装失败的问题 pip install numpy pip install scipy 后来网上搜寻了一番才得以解决.scipy 库需要依赖 numpy ...

  8. Python 机器学习库 NumPy 教程

    0 Numpy简单介绍 Numpy是Python的一个科学计算的库,提供了矩阵运算的功能,其一般与Scipy.matplotlib一起使用.其实,list已经提供了类似于矩阵的表示形式,不过numpy ...

  9. python scipy样条插值函数大全(interpolate里interpld函数)

    scipy样条插值 scipy样条插值1.样条插值法是一种以可变样条来作出一条经过一系列点的光滑曲线的数学方法.插值样条是由一些多项式组成的,每一个多项式都是由相邻的两个数据点决定的,这样,任意的两个 ...

随机推荐

  1. 【其他】msb-lsb-intel-motorola大小端问题

    MSB(Most Significant Bit) 最高有效位: LSB(Least Significant Bit) 最低有效位 intel格式:低字节在前 Motorola格式:高字节在前 参考1 ...

  2. android中的两种上下文区别

    1.this    继承于content      子类 2.getAppliCationContext()     返回值为context    父类 父类有的子类都有,子类父类不一定有. 在对话框 ...

  3. Gym - 101550A Artwork (并查集在线做法)

    题目链接 题意:给你一个n*m的网格图,初始时格点全白,每次可以将一段连续的格点涂黑.求出每次操作之后白色连通块的数量. 看了看网上的题解,基本全是离线的做法.其实这道题是有在线的做法的,利用了对偶图 ...

  4. 使用blessed 开发丰富的cli 应用

    blessed 是一个不错的npm 包,可以帮助我们开发出带有丰富ui界面的cli 应用,类似的有subzero 测试环境准备 项目结构 ├── README.md ├── app.js ├── my ...

  5. 遍历json 对象的属性并且动态添加属性

    昨天因为公司的一个需求,所以就研究了一下json对象的属性的遍历和动态修改: var person= { name: 'zhangsan', pass: '123' , 'sni.ni' : 'sss ...

  6. mockito框架

    2016-04-09 15:56:26 参考自 http://www.cnblogs.com/silence-hust/p/5017233.html http://blog.csdn.net/sdyy ...

  7. npm 使用

    npm 命令: 命令 作用 npm init 产生package.json文件 npm list <package> 查看安装的module版本 npm update <packag ...

  8. h5 的 audio 标签知识点

    因为音频格式有版权,各浏览器使用不同的音频格式. 音频格式兼容性 音频格式 Chrome Firefox IE9 Opera Safari MP3 支持 不支持 支持 不支持 支持 OGG 支持 支持 ...

  9. JSP中的MVC

    如下图

  10. R(2) sample

    sample: 从整体中挑出部分样本数据函数 Usage: sample.int(n, size = n, replace = FALSE, prob = NULL) x:可以是R中任何​对象 siz ...