• <bdo id='Eotcd'></bdo><ul id='Eotcd'></ul>

    <i id='Eotcd'><tr id='Eotcd'><dt id='Eotcd'><q id='Eotcd'><span id='Eotcd'><b id='Eotcd'><form id='Eotcd'><ins id='Eotcd'></ins><ul id='Eotcd'></ul><sub id='Eotcd'></sub></form><legend id='Eotcd'></legend><bdo id='Eotcd'><pre id='Eotcd'><center id='Eotcd'></center></pre></bdo></b><th id='Eotcd'></th></span></q></dt></tr></i><div id='Eotcd'><tfoot id='Eotcd'></tfoot><dl id='Eotcd'><fieldset id='Eotcd'></fieldset></dl></div>
    <legend id='Eotcd'><style id='Eotcd'><dir id='Eotcd'><q id='Eotcd'></q></dir></style></legend>

        <tfoot id='Eotcd'></tfoot>

        <small id='Eotcd'></small><noframes id='Eotcd'>

      1. 在 XY 网格中遵循 1/R 密度分布的点?

        Points that follow a 1/R density distribution in an XY grid?(在 XY 网格中遵循 1/R 密度分布的点?)

              <tbody id='Y9G8L'></tbody>
            <legend id='Y9G8L'><style id='Y9G8L'><dir id='Y9G8L'><q id='Y9G8L'></q></dir></style></legend>
            • <bdo id='Y9G8L'></bdo><ul id='Y9G8L'></ul>
              <i id='Y9G8L'><tr id='Y9G8L'><dt id='Y9G8L'><q id='Y9G8L'><span id='Y9G8L'><b id='Y9G8L'><form id='Y9G8L'><ins id='Y9G8L'></ins><ul id='Y9G8L'></ul><sub id='Y9G8L'></sub></form><legend id='Y9G8L'></legend><bdo id='Y9G8L'><pre id='Y9G8L'><center id='Y9G8L'></center></pre></bdo></b><th id='Y9G8L'></th></span></q></dt></tr></i><div id='Y9G8L'><tfoot id='Y9G8L'></tfoot><dl id='Y9G8L'><fieldset id='Y9G8L'></fieldset></dl></div>

              <small id='Y9G8L'></small><noframes id='Y9G8L'>

              <tfoot id='Y9G8L'></tfoot>

                1. 本文介绍了在 XY 网格中遵循 1/R 密度分布的点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 XY 网格,其中一些网格点具有分配给它们的某些值,在这种情况下,每个值都表示一定的质量,所以基本上是网格中的点质量.我现在想要获得一组遵循 1/R 密度分布的点,其中 R 是到中心的距离,所以 R = sqrt(x^2 + y^2).通过密度分布,我的意思是点的数量必须下降为 1/R.我将如何进行编码?

                  I have a XY grid with some gridpoints having certain values assigned to them, in this case, each value means a certain mass, so basically point masses in a grid. I now want to obtain a set of points which follow a density distribution of 1/R, where R is the distance from the center, so R = sqrt(x^2 + y^2). By density distribution, I mean the number of points has to fall off as 1/R. How would I go about coding this?

                  我的代码如下:

                  import numpy as np
                  x = np.linspace(-50,50,100)
                  y = np.linspace(-50,50,100)
                  X, Y = np.meshgrid(x,y)
                  zeta_a = (25,25)
                  zeta_b = (-10,5) 
                  M_a = 150
                  M_b = 150 
                  

                  zeta_a 和 zeta_b 对应于 2 个质量为 150 单位的点质量.我还需要使用这些点进行后续计算,所以我也想知道如何使用更通用的格式,而不是使用 'a'、'b'、'c' 来表示 n 点质量.

                  The zeta_a and zeta_b correspond to 2 point masses having masses of 150 units. I also need to perform follow up calculations using these points, so i'd also like to know how to use a more general format rather than using 'a','b','c' for n-point masses.

                  感谢您的帮助.

                  推荐答案

                  假设我理解你的问题(如果没有,欢迎评论):

                  Assuming I understood your question (if not comments are welcomed):

                  创建任何给定分布的方法是对分布 CDF 的逆进行插值.这是我的功能:

                  The way to create any given distribution is by interpolating over the inverse of the distribution CDF. This is my function to do it:

                  import numpy as np
                  import matplotlib.pyplot as plt
                  
                  def randdist(PDF, x, n):
                      """Create a distribution following PDF(x). PDF and x
                      must be of the same length. n is the number of samples."""
                      fp = np.random.rand(n,)
                      CDF = np.cumsum(PDF)
                      return np.interp(fp, CDF, x)
                  

                  现在,在您的情况下,我们将在极坐标中工作,R 分布为 1/r,Theta 均匀分布:

                  Now, in your case we're going to work in polar coordinates with R distributed as 1/r and Theta uniformly distributed:

                  num = 1000   # The number of points
                  r = np.linspace(-50, 50, 100)
                  PDF = np.abs(1/r)
                  PDF = PDF/np.sum(PDF)    # PDF should be normalized
                  R = randdist(PDF, r, num)
                  Theta = 2*np.pi*np.random.rand(num,)
                  

                  现在让我们创建点 x 和 y 向量

                  Now let's create the points x and y vectors

                  x = [R[k]*np.cos(Theta[k]) for k in range(num)]
                  y = [R[k]*np.sin(Theta[k]) for k in range(num)]
                  

                  绘制

                  plot(x,y,'.')
                  

                  请注意,在我的回答中,在 r=50 处有一个硬截止.有办法克服这个问题,但现在我保持原样.

                  Note that in my answer there is a hard cutoff at r=50. There are ways to overcome this but for now I leave it as it is.

                  现在您似乎还想将点嵌入到 2D 网格中,就像直方图一样.您可以使用

                  Now you seem to also want to embed the points inside a 2D grid, much like a histogram. You can do that using

                  z, _, _ = np.histogram2d(x, y, [100, 100])
                  

                  这篇关于在 XY 网格中遵循 1/R 密度分布的点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                      <tbody id='aAuy4'></tbody>

                    <tfoot id='aAuy4'></tfoot>

                      <legend id='aAuy4'><style id='aAuy4'><dir id='aAuy4'><q id='aAuy4'></q></dir></style></legend>
                      • <bdo id='aAuy4'></bdo><ul id='aAuy4'></ul>
                        • <i id='aAuy4'><tr id='aAuy4'><dt id='aAuy4'><q id='aAuy4'><span id='aAuy4'><b id='aAuy4'><form id='aAuy4'><ins id='aAuy4'></ins><ul id='aAuy4'></ul><sub id='aAuy4'></sub></form><legend id='aAuy4'></legend><bdo id='aAuy4'><pre id='aAuy4'><center id='aAuy4'></center></pre></bdo></b><th id='aAuy4'></th></span></q></dt></tr></i><div id='aAuy4'><tfoot id='aAuy4'></tfoot><dl id='aAuy4'><fieldset id='aAuy4'></fieldset></dl></div>
                          • <small id='aAuy4'></small><noframes id='aAuy4'>