
正文
python的cdf函数 python中cd怎么用
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
python没有直接生成服从泊松分布随机数的函数吗
首先是泊松分布python的cdf函数,这是一个离散型python的cdf函数的随机变量分布,比较好弄,此外例如考察一些到达事件的概率时,通常服从泊松分布,因此该分布相当实用。在开始编写之前,先感谢知乎一位大神的科普知识,假设有一个服从均匀分布的随机变量,u~U[0,1],F(x)为随机变量x的累计分布函数,那么F-1(u)的变量服从F分布,即F的逆函数是服从F的随机变量。代码如下python的cdf函数:
[java] view plain copy print?
span style="white-space:pre" /spanprivate static int getPossionVariable(double lamda) {
int x = 0;
double y = Math.random(), cdf = getPossionProbability(x, lamda);
while (cdf y) {
x++;
cdf += getPossionProbability(x, lamda);
}
return x;
}
private static double getPossionProbability(int k, double lamda) {
double c = Math.exp(-lamda), sum = 1;
for (int i = 1; i = k; i++) {
相关问答
Q1: 图像处理的Python问题,怎么解决
imtools.py里面也要有numpy 的引用才对
def histeq(im,nbr_bins=256):
"""对一幅灰度图像进行直方图均衡化"""
#计算图像的直方图
imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
cdf = imhist.cumsum() #累计分布函数
cdf = 255 * cdf / cdf[-1] #归一化
#使用累计分布函数的线性插值,计算新的像素
im2 = interp(im.flatten(),bins[:-1],cdf)
return im2.reshape(im.shape),cdf
以上代码我定义在imtools.py文件里并且放在了python2.7里
然后我在num.py里引用他
Python code?
1
2
3
4
5
6
7
8
9
10
from PIL import Image
from pylab import *
from numpy import *
import imtools
im= array(Image.open('E:\\daima\\pydaima\\shijue\\tupian1\\gang2.jpg').convert('L'))
im2,cdf =imtools.histeq(im)
出现以下错误:
Traceback (most recent call last):
File "pyshell#56", line 1, in module
a=imtools.histeq(im)
File "E:\daima\pydaima\shijue\imtools.py", line 32, in histeq
NameError: global name 'histogram' is not defined
Q2: python之字符串内置函数
1. 字符串字母处理
2. 字符串填充
str.ljust(width, fillchar)、str.center(width, fillchar)、str.rjust(width, fillchar)
返回一个指定的宽度 width 「居左」/「居中」/「居右」的字符串,如果 width 小于字符串宽度直接返回字符串,否则使用 fillchar 去填充。
3,字符串计数
str.count(sub, start, end)
#统计字符串里某个字符出现的次数。可选参数为在字符串搜索的开始与结束位置。
start, end遵循**“左闭右开”**原则。
4. 字符串位置
str.endswith(suffix, start, end)和str.startswith(substr, beg, end)
#判断字符串是否以指定后缀结尾/开头,如果以指定后缀「结尾」/「开头」返回 True,否则返回 False。
5. 字符串查找
6. 字符串判断
7. 字符串拼接
str.join() #将序列中的元素以指定的字符连接生成一个新的字符串。
s1 = "-" s2 = "" seq = ("r", "u", "n", "o", "o", "b")
# 字符串序列 print (s1.join( seq )) print (s2.join( seq )) r-u-n-o-o-b runoob
8. 统计字符串长度
str.len() #返回对象(字符、列表、元组等)长度或项目个数。
9. 去除字符两侧空格
str.lstrip()、str.rstrip()、str.strip() #截掉字符串「左边」/「右边」/「左右」两侧的空格或指定字符。
str0 = ' Hello World!' str0.lstrip() 'Hello World!' str1 = 'aaaa Hello World!' str1.lstrip('a') ' Hello World!'
10. str.maketrans(intab, outtab)和str.translate(table)
str.maketrans()创建字符映射的转换表
str.maketrans()根据参数table给出的表转换字符串的字符。
str.maketrans()传入的也可以是字典
tab = {'e': '3', 'o': '4'} trantab = str.maketrans(tab) str0.translate(trantab) 'H3ll4 W4rld!'
11. 字符串替换
str.replace(old, new, max)
12. 字符分割
str.split(str, num)
13. 字符填充
str.zfill(width)
返回指定长度的字符串,原字符串右对齐,前面填充0。
关于python的cdf函数和python中cd怎么用的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







