Python中是否存在用于检测一维数据中的步骤的现有实现?
例如,检测此数据中的一个步骤:
还有的算法相当多的描述在那里,但如果有什么适合的工作在Python存在我想知道?
我不确定是否/应该如何提供这些数据,但这里是:
[ 594. 568.55555556 577.22222222 624.55555556 546.66666667
552.88888889 575.55555556 592.33333333 528.88888889 576.11111111
625. 574.22222222 556.33333333 567.66666667 576.66666667
591.66666667 566.33333333 567.33333333 547.44444444 631.11111111
555.66666667 548.66666667 579.44444444 546.88888889 597.55555556
519.88888889 582.33333333 618.88888889 574.55555556 547.44444444
593.11111111 565.66666667 544.66666667 562.66666667 554.11111111
543.88888889 602.33333333 609.77777778 550.55555556 561.88888889
719.33333333 784.44444444 711.22222222 843.66666667 691.33333333
690.11111111 684.33333333 749.11111111 759.11111111 653.33333333
817.11111111 705.22222222 689.44444444 712.33333333 659.
683.88888889 713. 740.44444444 692.22222222 677.33333333
681.44444444 640. 717.55555556 717.88888889 769.22222222
690.88888889 786. 774.66666667 799.44444444 743.44444444
789.88888889 673.66666667 685.66666667 …Run Code Online (Sandbox Code Playgroud) 您可以按长度对列表进行排序,如下所示:
l1 = [1,2,3]
l2 = [1,2,3]
l3 = [1,2]
lists = [l1, l2, l3]
sorted_lists = sorted(lists, key=len)
print sorted_lists #[[1,2], [1,2,3], [1,2,3]]
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何跟踪标记,然后匹配sorted_lists原始列表名称的内容l1,l2和l3.
这很接近,但我不确定在按长度排序时如何实现解决方案.
我编写了一个程序,我试图使用PyInstaller变成可执行文件.Pyinstaller似乎已经完成没有任何错误,我最终得到了/ dist/my_program中的应用程序.但是,当我尝试运行该应用程序时,控制台窗口会闪回一秒钟并带有回溯:
编辑:我已经复制了追溯.可能有一个错误,因为我必须从屏幕截图中输入它,因为它只会闪烁.
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.pyplot", line 108, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends", line 32, in pylab_setup
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends.backend_tkagg", line 7, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 194, in load_module
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 108, in _resolve
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 779, in _import_module
ImportError: No module named FileDialog
Run Code Online (Sandbox Code Playgroud)
以下是我的代码中的导入:
import Tkinter
from tkFileDialog import askopenfilename
import numpy …Run Code Online (Sandbox Code Playgroud) 我试图在给定高斯的平均值和标准差的情况下获得两个边界之间高斯分布的积分。
import numpy as np
import scipy
mu = 5
sigma = 30
lowerbound = 0.5
upperbound = np.inf
# generate Gaussian function
x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100)
gauss = scipy.stats.norm.pdf(x, mu, sigma)
# integrate between bounds
integral = scipy.integrate.quad(gauss, lowerbound, upperbound)
Run Code Online (Sandbox Code Playgroud)
这引发了ValueError: invalid callable given,所以我做错了什么,但我不知道它是什么。
可以使用 PIL 将多页 tiff 保存到文件中:im.save(filepath, save_all=True)。我的问题是如何将 numpy 数组列表转换为 PIL 识别的 im 对象。im = PIL.Image.fromarray()不接受列表。
如何防止Tkinter小部件(特别是标签)的自动扩展?我的代码中有一个标签,我传递不同长度的字符串.如果字符串比列宽宽(使用网格布局管理器),我宁愿将它们移动到新行而不是拉伸列.下面是一些说明问题的代码.
import Tkinter
class window(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
self.columnconfigure(0, minsize=50)
self.columnconfigure(0, minsize=150)
self.rowconfigure(0,minsize=20)
self.rowconfigure(1,minsize=20)
self.rowconfigure(2,minsize=20)
self.labvar = Tkinter.StringVar()
self.lab = Tkinter.Label(self,bg='white',relief='groove',
textvariable=self.labvar)
self.lab.grid(row=0,column=0,rowspan=2,sticky='NSEW')
self.labvar.set("I don't want this to resize (Y dimension) ...")
self.but = Tkinter.Button(self, text='Click me!',command=self.onbut)
self.but.grid(row=2,column=0, sticky='NSEW')
def onbut(self):
self.labvar.set("I don't want this to resize (Y dimension) ...I'd rather this on a new line!")
if __name__ == "__main__":
app = window(None)
app.title('Window')
app.mainloop()
Run Code Online (Sandbox Code Playgroud)
作为一个快速的注释:避免self.labvar.set("我不...")线超过80个字符限制的正确方法是什么?我尝试使用"""并将其分成两行但是然后将字符串放入带有两行的标签中.
这里给出的答案解释了如何从中调整数组大小
[1,5,9]
[2,7,3]
[8,4,6]
Run Code Online (Sandbox Code Playgroud)
至
[1,1,5,5,9,9]
[1,1,5,5,9,9]
[2,2,7,7,3,3]
[2,2,7,7,3,3]
[8,8,4,4,6,6]
[8,8,4,4,6,6]
Run Code Online (Sandbox Code Playgroud)
使用np.repeat.鉴于较低的阵列,将它缩小到鞋面的最佳方法是什么?
python ×7
numpy ×2
python-2.7 ×2
tkinter ×2
arrays ×1
list ×1
nested-lists ×1
pyinstaller ×1
scipy ×1
sorting ×1
tiff ×1