小编sci*_*ci9的帖子

绘制归一化均匀混合物

我需要在下面重现归一化密度 p(x),但给出的代码不会生成归一化 PDF。

x 的 p 绘图

clc, clear
% Create three distribution objects with different parameters
pd1 = makedist('Uniform','lower',2,'upper',6);
pd2 = makedist('Uniform','lower',2,'upper',4);
pd3 = makedist('Uniform','lower',5,'upper',6);
% Compute the pdfs
x = -1:.01:9;
pdf1 = pdf(pd1,x); 
pdf2 = pdf(pd2,x); 
pdf3 = pdf(pd3,x); 
% Sum of uniforms
pdf = (pdf1 + pdf2 + pdf3);
% Plot the pdfs
figure;
stairs(x,pdf,'r','LineWidth',2);
Run Code Online (Sandbox Code Playgroud)

如果我通过简单地按它们的总和缩放它们来计算归一化混合 PDF,与上面的原始图相比,我有不同的归一化概率。

pdf = pdf/sum(pdf);
Run Code Online (Sandbox Code Playgroud)

matlab distribution probability-density uniform-distribution mixture

4
推荐指数
1
解决办法
420
查看次数

Python正则表达式:如何选择两个模式之间的行

考虑如下典型的实时聊天数据:

Peter (08:16): 
Hi 
What's up? 
;-D

Anji Juo (09:13): 
Hey, I'm using WhatsApp!

Peter (11:17):
Could you please tell me where is the feedback?

Anji Juo (19:13): 
I don't know where it is. 

Anji Juo (19:14): 
Do you by any chance know where I can catch a taxi ?

Run Code Online (Sandbox Code Playgroud)

要将这个原始文本文件转换为 DataFrame,我需要编写一些正则表达式来识别列名称,然后提取相应的值。

请参阅https://regex101.com/r/X3ubqF/1

Index(time)     Name        Message
08:16           Peter       Hi 
                            What's up? 
                            ;-D
09:13           Anji Juo    Hey, I'm using WhatsApp!
11:17           Peter       Could you please tell me where is the …
Run Code Online (Sandbox Code Playgroud)

python regex nlp dataframe pandas

4
推荐指数
1
解决办法
966
查看次数

为什么 MATLAB 的 rgb2hsv 返回错误的色调值?

考虑下图:

图片

下面的 MATLAB 代码返回色调值的直方图:

img1 = imread('img.png');  
img1(img1<1) = 0;
%
img_hsv = rgb2hsv(img1);
hue_img = img_hsv(:,:,1);
array = hue_img(hue_img > 0.1);
histfit(array, 20)
Run Code Online (Sandbox Code Playgroud)

MATLAB 输出

它返回错误的 Hue 值,但 Python 中的等效代码返回正确的值。

import cv2 
import matplotlib.pyplot as plt
import numpy as np
from skimage import data
from skimage.color import rgb2hsv

img = cv2.imread(r"img.png") 
rgb_img = img 
hsv_img = rgb2hsv(rgb_img) 
hue_img = hsv_img[:, :, 0] 
hue_img[np.where(hue_img > 0.1)] 
array = hue_img[np.where(hue_img > 0.1)] 
plt.hist(array,bins=100)
Run Code Online (Sandbox Code Playgroud)

蟒蛇输出

通过在任何图像编辑软件中使用颜色选择器工具,我们可以看到正确的色相值大约是 100 中的 50 或 1 中的 0.5。

截屏

我们如何从 MATLAB …

python matlab colors image-processing

1
推荐指数
1
解决办法
267
查看次数