小编drz*_*bir的帖子

如何在圆中生成齐次泊松点过程?

我想在圆心 (0,0) 和半径 R=200 的圆 C 中生成 N 个点。这些点遵循泊松分布。换句话说,我想在 C 中生成 N 个齐次泊松点过程(HPPP)。

我发现了这篇论文生成均匀泊松过程。在第 2 节中,正是我想要的。具体来说,在第 4 页中,算法 3 在 C 内部生成点 HPPP。

我在 Python 中实现了这段代码,如下所示:

""" Main Codes """    
import matplotlib.pyplot as plt
import numpy as np


lamb = 0.0005 # the rate
pi = np.pi # pi = 3.14...
r = 200 # the radius of the circle C
mean = lamb * pi * r ** 2 # the mean of the Poisson random variable …
Run Code Online (Sandbox Code Playgroud)

python poisson

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

如何通过Python中行的总和按升序对矩阵进行排序?

完全相同的问题在这里得到解答,但在MATLAB中.

我的问题是:给定矩阵,根据行的总和按升序对其进行排序.也就是说,如果A是以下矩阵:

A = [[9, 8, 7],
     [2, 5, 7], 
     [1, 3, 4]]
Run Code Online (Sandbox Code Playgroud)

因此,我会得到:

B = [[1, 3, 4],
     [2, 5, 7], 
     [9, 8, 7]]
Run Code Online (Sandbox Code Playgroud)

由于第1行的总和A24,对第二行的总和A14,和第3行的总和A8.因此,第1行将B是第3行A,第2行将B是第2行A,第3行将B是第1行A.

我正在寻找一种使用内置功能的解决方案(如果可能的话).我不是在寻找一种算法.

python

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

如何在Python中生成0-1矩阵的所有可能组合?

如何生成大小为K的0-1矩阵的所有可能组合?

例如,如果我取K = 2且N = 2,我得到以下组合.

combination 1
[0, 0;
 0, 0]; 
combination 2
[1, 0;
 0, 0]; 
combination 3
[0, 1;
 0, 0]; 
combination 4
[0, 0;
 1, 0]; 
combination 5
[0, 0;
 0, 1]; 
combination 6
[1, 1;
 0, 0]; 
combination 7
[1, 0;
 1, 0]; 
combination 8
[1, 0;
 0, 1]; 
combination 9
[0, 1;
 1, 0]; 
combination 10
[0, 1;
 0, 1]; 
combination 11
[0, 0;
 1, 1]; 
combination 12
[1, 1;
 1, 0]; 
combination 13 …
Run Code Online (Sandbox Code Playgroud)

python combinations

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

如何在Julia中按值从数组中删除元素?

我在Julia中有一个简单的程序:

a = [1, 2, 3, 10, 20, 30]
delete!(a, 10)
Run Code Online (Sandbox Code Playgroud)

但它不起作用。错误是MethodError: no method matching delete!(::Array{Int64,1}, ::Int64)

我可以看到deleteat!splice!接受索引而不是值。

如何10aJulia中的数组中删除元素?

julia

2
推荐指数
2
解决办法
5671
查看次数

如何在Python中的while循环中修复此错误?

我在Python中有一个列表list1,以及以下while循环:

j = 0
while list1[j] >= list1[j - 1] and j < len(list1):
    # do something here and return k
    # k is always incremented
    j += k
Run Code Online (Sandbox Code Playgroud)

我收到以下错误: IndexError: string index out of range

如何解决这个错误?

python

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

标签 统计

python ×4

combinations ×1

julia ×1

poisson ×1