Python3科学计算库概况
Python3科学计算常见库入门
Numpy快速数据处理库
参见我的博客
http://www.cnblogs.com/brightyuxl/p/8981294.html
http://www.cnblogs.com/brightyuxl/p/8977075.html
http://www.cnblogs.com/brightyuxl/p/8855948.html
http://www.cnblogs.com/brightyuxl/p/8846701.html
SciPy数值计算库
常数和特殊函数
from scipy import constants
print('真空中的光速:{}'.format(constants.c))
print('普朗克常数: {}'.format(constants.h))
print('电子质量(数值,单位,误差): {}'.format(constants.physical_constants['electron mass']))
真空中的光速:299792458.0
普朗克常数: 6.62607004e-34
电子质量(数值,单位,误差): (9.10938356e-31, 'kg', 1.1e-38)
特殊函数
Gamma函数\(\Gamma\)是统计学中经常出现的一个特殊函数:
\]
import scipy.special
print(scipy.special.gamma(0))
print(scipy.special.gamma(0.5))
print(scipy.special.gamma(1))
print(scipy.special.gamma(1.5))
print(scipy.special.gamma(2))
inf
1.7724538509055159
1.0
0.8862269254527579
1.0
\(\ln(|\Gamma(x)|)\)可以计算更大的数
scipy.special.gammaln(1000)
5905.220423209181
import numpy as np
print(1+1e-20)
print(np.log(1+1e-20))
print(scipy.special.log1p(1e-20)) # log1p(x) = log(1+x)
1.0
0.0
1e-20
matplotlib快速绘图库
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 1000)
y = np.sin(x)
z = np.cos(x**2)
plt.figure(figsize=(8,4))
plt.plot(x,y,label='$sin(x)$', color='red',linewidth=2)
plt.plot(x,z,'b--',label='$cos(x^2)$')
plt.xlabel('Time(s)')
plt.ylabel('Volt')
plt.title('PyPlot First Example')
plt.ylim(-1.2,1.2)
plt.legend
plt.savefig('My_figure')
plt.show()

Pandas数据分析友好库
import pandas as pd
s = pd.Series([1,2,3,4,5,6], index=['a','b','c','d','e','f'])
print(s)
a 1
b 2
c 3
d 4
e 5
f 6
dtype: int64
SymPy符号运算库
\]
from sympy import E, I, pi
E**(I*pi) + 1 # 证明欧拉等式
0
from sympy import symbols, expand
x = symbols('x')
expand(E**(I*x))
exp(I*x)
Python3小知识点
1.写函数,计算传入字符串中【数字】、【字母】、【空格] 以及 【其他】的个数
其实人跟树一样,越是向往高处的阳光,它的根就越要伸向黑暗的地底。
def StringCounter(seq):
dic = {
'num':0,
'string':0,
'space':0,
'other':0
}
for s in seq:
if s.isdigit():
dic['num'] += 1
elif s.isalpha():
dic['string'] += 1
elif s.isspace():
dic['space'] += 1
else:
dic['other'] += 1
return dic
# 验证函数
print(StringCounter('dfasfdaslfkjl 12312 @@!#!@#'))
{'num': 5, 'string': 13, 'space': 5, 'other': 7}
2.分析下列代码的运行过程
x=1
def f1():
def f2():
print(x)
return f2
x=100
def f3(func):
x=2
func()
x=10000
f3(f1())
10000
3.查看a与b的不同之处
a = [1,2,3]
b = [(1),(2),(3)]
print(a == b)
print(a is b)
True
False
4.切片回忆
name = ['trek', 'cannondale', 'redline', 'specialized', 'trek']
print('1:', name)
print('2:', name[0], name[2])
print('3:', name[1:3]) #切片
print('4:', name[-2:]) #切片
print('5:', name[::-1]) #切片的结果是倒序排列
print('6:', name[:-1]) #切片的结果是,输出到倒数第二位 -1-1=-2
1: ['trek', 'cannondale', 'redline', 'specialized', 'trek']
2: trek redline
3: ['cannondale', 'redline']
4: ['specialized', 'trek']
5: ['trek', 'specialized', 'redline', 'cannondale', 'trek']
6: ['trek', 'cannondale', 'redline', 'specialized']
Python3科学计算库概况的更多相关文章
- SciPy - 科学计算库(上)
SciPy - 科学计算库(上) 一.实验说明 SciPy 库建立在 Numpy 库之上,提供了大量科学算法,主要包括这些主题: 特殊函数 (scipy.special) 积分 (scipy.inte ...
- python科学计算库的numpy基础知识,完美抽象多维数组(原创)
#导入科学计算库 #起别名避免重名 import numpy as np #小技巧:从外往内看==从左往右看 从内往外看==从右往左看 #打印版本号 print(np.version.version) ...
- python科学计算库numpy和绘图库PIL的结合,素描图片(原创)
# 导入绘图库 from PIL import Image #导入科学计算库 import numpy as np #封装一个图像处理工具类 class TestNumpy(object): def ...
- numpy科学计算库的基础用法,完美抽象多维数组(原创)
#起别名避免重名 import numpy as np #小技巧:print从外往内看==shape从左往右看 if __name__ == "__main__": print(' ...
- Python科学计算库
Python科学计算库 一.numpy库和matplotlib库的学习 (1)numpy库介绍:科学计算包,支持N维数组运算.处理大型矩阵.成熟的广播函数库.矢量运算.线性代数.傅里叶变换.随机数生成 ...
- ubuntu14.04 下安装 gsl 科学计算库
GSL(GNU Scientific Library)作为三大科学计算库之一,除了涵盖基本的线性代数,微分方程,积分,随机数,组合数,方程求根,多项式求根,排序等,还有模拟退火,快速傅里叶变换,小波, ...
- windows下如何快速优雅的使用python的科学计算库?
Python是一种强大的编程语言,其提供了很多用于科学计算的模块,常见的包括numpy.scipy.pandas和matplotlib.要利用Python进行科学计算,就需要一一安装所需的模块,而这些 ...
- Python科学计算库Numpy
Python科学计算库Numpy NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库. 1.简 ...
- 科学计算库Numpy基础&提升(理解+重要函数讲解)
Intro 对于同样的数值计算任务,使用numpy比直接编写python代码实现 优点: 代码更简洁: numpy直接以数组.矩阵为粒度计算并且支持大量的数学函数,而python需要用for循环从底层 ...
随机推荐
- MCS-51单片机存储地址空间划分
1.前言 MCS-51的存储器有片内RAM.片外RAM 和 ROM 三个空间. MCS-51单片机在物理结构上有四个存储空间 1.片内程序存储器(片内ROM)2.片外程序存储器(片外ROM)3.片内数 ...
- git获取内核源码的方法
[转]http://www.360doc.com/content/17/0410/16/23107068_644444795.shtml 1. 前言 本文主要讲述ubuntu下通过git下载linux ...
- 移动端中遇到的坑(bug)!!!
1.模拟单选点击的时候,在ios手机下,点击下面的内容选择,会出现页面闪一闪!! 解决方案:样式重置html的时候加上这句 -webkit-tap-highlight-color: rgba(0, ...
- Centos6.5使用yum安装mysql——快速上手必备
第1步.yum安装mysql [root@stonex ~]# yum -y install mysql-server 安装结果: Installed: mysql-server.x86_6 ...
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
- http转发
该http转发,我感觉有点类似于负载均衡(我还没有详细了解过负载均衡). 现在有三个站点,想自己建立一个web,对三个站点进行整合,效果如图所示: a)现状:浏览器需要访问3个站点,需要记住3个地址, ...
- FreeSWITCH Git版本管理
由于测试FreeSWITCH不同版本的需要,研究了下Git的使用,通过Git来管理所有的版本,方便了测试.以下就总结下具体的使用方法: 其中:git clone ..是现在git仓库:git tag ...
- BN(Batch Normalization)
Batch Nornalization Question? 1.是什么? 2.有什么用? 3.怎么用? paper:<Batch Normalization: Accelerating Deep ...
- hdu5256 二分求LIS+思维
解题的思路很巧,为了让每个数之间都留出对应的上升空间,使a[i]=a[i]-i,然后再求LIS 另外二分求LIS是比较快的 #include<bits/stdc++.h> #define ...
- js字符串转换成数字与数字转换成字符串的实现方法
转载:点击查看地址 js字符串转换成数字 将字符串转换成数字,得用到parseInt函数.parseInt(string) : 函数从string的开始解析,返回一个整数. 举例:parseInt(' ...