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. Pycharm出现的部分快捷键无效问题及解决办法

    为了进行python开发,下载了Pycharm.但是发现启动后,执行ctrl+c和ctrl+v等快捷键都无法生效. 网上搜索了下,参考https://blog.csdn.net/c2366994582 ...

  2. GPA

    原题: GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  3. BZOJ3771: Triple【生成函数】

    Description 我们讲一个悲伤的故事. 从前有一个贫穷的樵夫在河边砍柴. 这时候河里出现了一个水神,夺过了他的斧头,说: "这把斧头,是不是你的?" 樵夫一看:" ...

  4. HDU 4548:美素数

    Problem Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素 ...

  5. java泛型学习(2)

    一:深入泛型使用.主要是父类和子类存在泛型的demo /** * 父类为泛型类 * @author 尚晓飞 * @date 2014-7-15 下午7:31:25 * * * 父类和子类的泛型. * ...

  6. redis-benchmark压力测试

    redis-benchmark是redis官方提供的压测工具,安装好redis后,默认安装.使用简便. 语法: Usage: redis-benchmark [-h <host>] [-p ...

  7. 检索关键字 nyoj

    检索关键字 时间限制: 1000ms 内存限制: 65536KB 64位整型:      Java 类名: 上一题 提交 运行结果 统计 讨论版 下一题 类型: 没有   没有   难度        ...

  8. [LeetCode系列] 双单链表共同节点搜索问题

    找到两个单链表的共同节点. 举例来说, 下面两个链表A和B: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 共同节点为c1. 分析: 共同节点距离A,B的起点 ...

  9. ASM 磁盘、目录的管理

    --======================== -- ASM 磁盘.目录的管理 --======================== ASM磁盘是ASM体系结构的重要组成部分,ASM磁盘由ASM ...

  10. IE浏览器从页面向后台Controller传中文值出现乱码问题

    地址前面添加encodeURI() 1. var url = encodeURI('xxxAction.action?para='+中文); $('#cc').combobox({ url : url ...