对于想了解在Python中生成3D希尔伯特空间填充曲线的算法的读者,本文将是一篇不可错过的文章,我们将详细介绍在python中生成3d希尔伯特空间填充曲线的算法,并且为您提供关于GeoHash与空间填
对于想了解在Python中生成3D希尔伯特空间填充曲线的算法的读者,本文将是一篇不可错过的文章,我们将详细介绍在python中生成3d希尔伯特空间填充曲线的算法,并且为您提供关于GeoHash与空间填充曲线、Java中空间填充Hilbert曲线的递推算法、python – 如何在seaborn分布图中填充曲线下面积、使用过滤器和生成器在python中生成无穷素数的有价值信息。
本文目录一览:- 在Python中生成3D希尔伯特空间填充曲线的算法(在python中生成3d希尔伯特空间填充曲线的算法)
- GeoHash与空间填充曲线
- Java中空间填充Hilbert曲线的递推算法
- python – 如何在seaborn分布图中填充曲线下面积
- 使用过滤器和生成器在python中生成无穷素数
在Python中生成3D希尔伯特空间填充曲线的算法(在python中生成3d希尔伯特空间填充曲线的算法)
我想将RGB颜色立方体中的点映射到Python中的一维列表,以使颜色列表看起来美观且连续的方式。
我相信使用3D希尔伯特空间填充曲线将是实现此目的的一种好方法,但是我进行了搜索,但尚未找到解决此问题的有用资源。维基百科尤其仅提供用于生成2D曲线的示例代码。
答案1
小编典典本文似乎进行了相当多的讨论: 三维希尔伯特空间填充曲线清单。
引用摘要:
希尔伯特的二维空间填充曲线因其在许多应用中的良好局部性而受到赞赏。但是,尚不清楚将曲线通用化以填充高维空间的最佳方法是什么。我们认为,使希尔伯特曲线在两个维度上独一无二的特性,在三个维度上都由10694807结构上不同的空间填充曲线所共享。
GeoHash与空间填充曲线
看了一下GeoHash,怎么看都是一个莫顿编码(Morton Code)。
而莫顿编码也是一个Z-order曲线。 空间填充曲线除了Z-order以往还有,Hilbert曲线,Peano曲线。 这些都可以用来作为把二维映射到一维的空间索引。
瓦片编码的基本要求是相邻的瓦片编码相似,这样缓存更友好。
Java中空间填充Hilbert曲线的递推算法
public class HilbertCurve extends JPanel { int N; /** * Constructor for Hilbert Curve */ public HilbertCurve () { Scanner myKeyboard = new Scanner(system.in); System.out.println("Enter an integer number to indicate the level of recursive depth: "); N = myKeyboard.nextInt(); // Create a JFrame - a window that will appear on your screen JFrame f = new JFrame(); // Tells the program to quit if you close the window f.setDefaultClo@R_301_6197@peration(JFrame.EXIT_ON_CLOSE); // Puts your drawing into the window (the JFrame) f.add(new JScrollPane(this)); // Changes the size of the window on the screen f.setSize(600,600); // Changes where the window will appear on your screen f.setLocation(200,200); // Makes the window appear f.setVisible(true); } public void setupHilbert (Turtle turtle) { turtle.penup(); turtle.setXY(0,0); // draw a simple rectangle that is 100x50 pixels turtle.pendown(); drawHilbert(turtle,N); } public void drawHilbert(Turtle turtle,int n) { if (n == 0) return; turtle.changeColor(Color.GREEN); turtle.changeWidth(2); turtle.left(-90); turtle.forward(100); turtle.left(90); turtle.forward(100); turtle.left(90); turtle.forward(100); turtle.left(-90); turtle.penup(); } protected void paintComponent(Graphics g) { Turtle turtle = new Turtle((Graphics2D) g,getBounds()); turtle.setheadingMode(Turtle.DEGREE); setupHilbert(turtle); } // plot a Hilbert curve of order N public static void main(String[] args) { Scanner myKeyboard = new Scanner(system.in); HilbertCurve test = new HilbertCurve(); }
}
解决方法
密切注意你的停止条件,否则你最终会得到一个OutOfMemoryError,因为递归调用会永久地添加到堆栈中.
我不熟悉你的问题,但这会是你错过的吗?
public void drawHilbert(Turtle turtle,int n) { if (n == 0) return; turtle.changeColor(Color.GREEN); turtle.changeWidth(2); turtle.left(-90); turtle.forward(100); turtle.left(90); turtle.forward(100); turtle.left(90); turtle.forward(100); turtle.left(-90); turtle.penup(); drawHilbert(turtle,--n); // is this where your recursion should go? }
更新:这个网站看起来很相关.
http://people.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-2_themes-hilbert-sec.html
python – 如何在seaborn分布图中填充曲线下面积
x = [1.883830,7.692308,8.791209,9.262166] y = [5.337520,4.866562,2.825746,6.122449]
而且我想使用包裹在matplotlib中的seaborn来拟合高斯分布.似乎sns.distplot函数是执行此操作的最佳方法,但我无法弄清楚如何填充曲线下方的区域.救命?
fig,ax = plt.subplots(1) sns.distplot(x,kde_kws={"shade":True},kde=False,fit=stats.gamma,hist=None,color="red",label="2016",fit_kws={'color':'red'}); sns.distplot(y,color="blue",label="2017",fit_kws={'color':'blue'})
我认为“阴影”参数可能是fit_kws参数的一部分,但我没有得到这个.
另一种选择是使用ax.fill()?
解决方法
import numpy as np import seaborn as sns import scipy.stats as stats import matplotlib.pyplot as plt x = [1.883830,6.122449] ax = sns.distplot(x,fit_kws={"color":"red"},label="label 1"); ax = sns.distplot(y,fit_kws={"color":"blue"},label="label 2"); # Get the two lines from the axes to generate shading l1 = ax.lines[0] l2 = ax.lines[1] # Get the xy data from the lines so that we can shade x1 = l1.get_xydata()[:,0] y1 = l1.get_xydata()[:,1] x2 = l2.get_xydata()[:,0] y2 = l2.get_xydata()[:,1] ax.fill_between(x1,y1,alpha=0.3) ax.fill_between(x2,y2,alpha=0.3) plt.show(block=False)
结果如下所示:
使用过滤器和生成器在python中生成无穷素数
以下是我发现的使用Eratosthenes筛子查找素数的python程序。它使用过滤器和生成器。我听不懂
def _odd_iter(): n = 1 while True: n = n + 2 yield ndef _not_divisible(n): return lambda x: x % n > 0def primes(): yield 2 it = _odd_iter() while True: n = next(it) yield n it = filter(_not_divisible(n), it)for n in primes(): if n < 1000: print(n) else: break
我不明白的是it = filter(_not_divisible(n), it)
。例如,对于数字105,如何用单行代码排除它?
答案1
小编典典对于找到的每个素数,将a filter
应用于可迭代对象,所使用的过滤器是一项功能,它排除素数的所有倍数。
因此,您的可迭代项被包裹在与找到质数一样多的过滤器中,例如,排除了数字105,因为它可以被3整除,并且在找到质数3时添加了3的所有倍数的过滤器。
如果添加一些print
语句,它将更加清晰(我希望):
def _odd_iter(): n = 1 while True: n = n + 2 yield ndef _not_divisible(n): print(''add filter for all multiples of'', n) return lambda x: print(''check if'', x, ''is divisible by'', n, ''result: '', not (x % n > 0)) or x % n > 0def primes(): yield 2 it = _odd_iter() while True: n = next(it) yield n it = filter(_not_divisible(n), it)for n in primes(): if n < 20: print(n) else: break
打印:
23add filter for all multiples of 3check if 5 is divisible by 3 result: False5add filter for all multiples of 5check if 7 is divisible by 3 result: Falsecheck if 7 is divisible by 5 result: False7add filter for all multiples of 7check if 9 is divisible by 3 result: Truecheck if 11 is divisible by 3 result: Falsecheck if 11 is divisible by 5 result: Falsecheck if 11 is divisible by 7 result: False11add filter for all multiples of 11check if 13 is divisible by 3 result: Falsecheck if 13 is divisible by 5 result: Falsecheck if 13 is divisible by 7 result: Falsecheck if 13 is divisible by 11 result: False13add filter for all multiples of 13check if 15 is divisible by 3 result: Truecheck if 17 is divisible by 3 result: Falsecheck if 17 is divisible by 5 result: Falsecheck if 17 is divisible by 7 result: Falsecheck if 17 is divisible by 11 result: Falsecheck if 17 is divisible by 13 result: False17add filter for all multiples of 17check if 19 is divisible by 3 result: Falsecheck if 19 is divisible by 5 result: Falsecheck if 19 is divisible by 7 result: Falsecheck if 19 is divisible by 11 result: Falsecheck if 19 is divisible by 13 result: Falsecheck if 19 is divisible by 17 result: False19add filter for all multiples of 19check if 21 is divisible by 3 result: Truecheck if 23 is divisible by 3 result: Falsecheck if 23 is divisible by 5 result: Falsecheck if 23 is divisible by 7 result: Falsecheck if 23 is divisible by 11 result: Falsecheck if 23 is divisible by 13 result: Falsecheck if 23 is divisible by 17 result: Falsecheck if 23 is divisible by 19 result: False
今天的关于在Python中生成3D希尔伯特空间填充曲线的算法和在python中生成3d希尔伯特空间填充曲线的算法的分享已经结束,谢谢您的关注,如果想了解更多关于GeoHash与空间填充曲线、Java中空间填充Hilbert曲线的递推算法、python – 如何在seaborn分布图中填充曲线下面积、使用过滤器和生成器在python中生成无穷素数的相关知识,请在本站进行查询。
本文标签: