我有以下代码:
public class SomeClass {
//InterfaceUpdateListener is an interface
private InterfaceUpdateListener listener = new InterfaceUpdateListener(){
public void onUpdate() {
SomeClass.this.someMethod(); //complier complains on this line of code
}
};
private void someMethod() {
//do something in here on an update event occuring
}
//other code to register the listener with another class...
}
Run Code Online (Sandbox Code Playgroud)
我在 Eclipse 中的编译器抱怨说
Access to enclosing method 'someMethod' from type SomeClass is emulated by a synthetic accessor method.
谁能准确解释一下
谢谢
我试图嵌入一个matplotlib图,每秒更新一次PyQt GUI主窗口.
在我的程序中,我threading.Timer通过timer下面显示的函数每秒调用一次更新函数.我有一个问题:我的程序每秒都会变大 - 每4秒钟大约1k.我最初的想法是append函数(返回一个新数组update_figure)不会删除旧数组?这可能是我问题的原因吗?
def update_figure(self):
self.yAxis = np.append(self.yAxis, (getCO22()))
self.xAxis = np.append(self.xAxis, self.i)
# print(self.xAxis)
if len(self.yAxis) > 10:
self.yAxis = np.delete(self.yAxis, 0)
if len(self.xAxis) > 10:
self.xAxis = np.delete(self.xAxis, 0)
self.axes.plot(self.xAxis, self.yAxis, scaley=False)
self.axes.grid(True)
self.i = self.i + 1
self.draw()
Run Code Online (Sandbox Code Playgroud)
这是我的计时器功能 - 这是通过点击我的PyQt GUI中的按钮触发,然后调用自己,如您所见:
def timer(self):
getCH4()
getCO2()
getConnectedDevices()
self.dc.update_figure()
t = threading.Timer(1.0, self.timer)
t.start()
Run Code Online (Sandbox Code Playgroud)
编辑:我无法发布我的整个代码,因为它需要很多.dll包含.所以我将尝试解释这个程序的功能.
在我的GUI中,我想显示我的CO 2值随着时间的推移.我的get_co22函数只返回一个浮点值,我100%肯定这个工作正常.使用我的计时器,如上所示,我想继续为matplotlib图添加一个值 - 该Axes对象可供我使用self.axes.我尝试绘制数据的最后10个值.
编辑2:在聊天中进行了一些 …
I have the following problem and I am totally new to matplotlib and python: To produce high qualitiy plots for my thesis I want to use matplotlib and I want to use the latex commands for the axes etc. When I try the following example (from http://matplotlib.org/users/usetex.html#usetex-tutorial):
import numpy as np
import matplotlib.pyplot as plt
# Example data
t = np.arange(0.0, 1.0 + 0.01, 0.01)
s = np.cos(4 * np.pi * t) + 2
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.plot(t, …Run Code Online (Sandbox Code Playgroud) 我最近用Python替换了Matlab因为我是真的;因为Sympy而兴奋.
但现在我有以下问题:
我需要一种用Python可靠地计算连续傅里叶变换的方法.Sympy在解决方案方面存在问题,包括Diracs(Delta函数),因为它们例如出现在三角函数等处.
例如,如果我尝试
fourier_transform(cos(x),x,v)
Run Code Online (Sandbox Code Playgroud)
输出0应该基于Dirac delta函数
有没有人知道,如果Sympy的这一部分有待改进,或者是否有其他方法可以通过Python分析性地找到傅立叶变换?
感谢您提前给出答案或任何建议!
为什么当代码通过python运行时,图形似乎在y轴上以10 ^ -1分解?(下面的代码)
from pylab import *
bins = [+0.000e+00,+1.000e+00,+2.000e+00,+3.000e+00,+4.000e+00,+5.000e+00]
wght = [[+3.000e-02,+7.0e-02,+3.0e-01,+5.0e-01,+8.0e-01]]
hist([ bins[:-1] for i in range(len(wght)) ], bins=bins, weights=wght,histtype="stepfilled", log=True )
ylim(bottom=0.01); ylim(top=1.0)
savefig("./output.pdf")
Run Code Online (Sandbox Code Playgroud)
它实际上是什么样的:
我目前在Xubuntu 14.04上运行python 2.7,这个错误发生在很多直方图上.出于某种原因,当在Windows上打开并运行Python(x,y)时,我们得到第一个直方图(它应该是什么样子)但是当我在Xubuntu上移动到python时,我尝试运行的所有图形都与此类似在y轴上的10 ^ -1.(它实际上是什么样的)我可以用这个代码做什么来确保它在我想要运行的任何python版本上输出第一个gyazo图片?
在阅读一些CTF写作时,我遇到了这个脚本
#!/usr/bin/env python
import struct
import Image
import dpkt
INIT_X, INIT_Y = 100, 400
def print_map(pcap, device):
picture = Image.new("RGB", (1200, 500), "white")
pixels = picture.load()
x, y = INIT_X, INIT_Y
for ts, buf in pcap:
device_id, = struct.unpack("b", buf[0x0B])
if device_id != device:
continue
data = struct.unpack("bbbb", buf[-4:])
status = data[0]
x = x + data[1]
y = y + data[2]
if (status == 1):
for i in range(-5, 5):
for j in range(-5, 5):
pixels[x + i , …Run Code Online (Sandbox Code Playgroud) 我知道很多关于垃圾收集的问题,我已经完成了它们,但我仍然有一些疑问.
如果我们不能强制JVM进行垃圾收集那么需要System.gc()什么?它在哪种情况下有用?
我知道年轻一代[eden,SO,S1]和老一代以及物体如何从年轻一代转移到老一代.何时将对象移动到永久生成?例如,我有mycar一个引用的对象,并且不符合垃圾收集的条件,所以什么时候mycar对象会在永久生成中移动?
我已经读过静态变量存储在永久生成中.什么时候它们会被垃圾收集以及永久生成哪种类型的其他物品?为什么静态变量存储在永久生成中以及永久生成的用途是什么?
我知道对象存储在堆内存中.这是真的,每个应用程序都有自己的堆内存吗?
Calling是否会System.gc()降低应用程序性能并降低我们的应用程序速度?或者,当JVM完成垃圾收集时,它会降低应用程序性能并使我们的应用程序工作缓慢?
在哪些情况下,部分垃圾收集完成,何时进行主要垃圾收集?
我有一个庞大的数据集,我希望PCA.我受限于RAM和PCA的计算效率.因此,我转而使用Iterative PCA.
数据集大小 - (140000,3504)
该文件指出,This algorithm has constant memory complexity, on the order of batch_size, enabling use of np.memmap files without loading the entire file into memory.
这真的很好,但不确定如何利用这一点.
我尝试加载一个memmap,希望它能以块的形式访问它,但是我的RAM已经爆炸了.我下面的代码最终使用了大量的RAM:
ut = np.memmap('my_array.mmap', dtype=np.float16, mode='w+', shape=(140000,3504))
clf=IncrementalPCA(copy=False)
X_train=clf.fit_transform(ut)
Run Code Online (Sandbox Code Playgroud)
当我说"我的RAM吹"时,我看到的Traceback是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sklearn\base.py", line 433, in fit_transfo
rm
return self.fit(X, **fit_params).transform(X)
File "C:\Python27\lib\site-packages\sklearn\decomposition\incremental_pca.py",
line 171, in fit
X = check_array(X, dtype=np.float)
File "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 347, in
check_array
array …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成一个盒子图.这是我的代码,数据如下:
def loadData(fileName):
data = pd.read_csv(fileName, quotechar='"')
cols = data.columns.tolist()
cols = cols[1:] + [ cols[0] ]
data = data[cols]
return data.values
cols={}
cols['close/last']=0
cols['volumne']=1
cols['open']=2
cols['high']=3
cols['low']=4
cols['date']=5
fileName = 'microsoft.csv'
def boxplot():
data1 = loadData(fileName)
ithattr1 = cols['high']
ithattr2 = cols['close/last']
dataset1 = data1[:,ithattr1]
dataset2 = data1[:,ithattr2]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.boxplot([dataset1,dataset2])
plt.show()
boxplot()
Run Code Online (Sandbox Code Playgroud)
数据是浮点数,由输出的print命令验证
<type 'float'>.在运行代码时,我收到以下错误(下面的完整堆栈跟踪)
AttributeError: 'numpy.ndarray' object has no attribute 'find'
我的数据(例如in dataset1)看起来像这样
[52.21 52.2 52.44 52.65 52.33 51.58 51.38 51.68 …Run Code Online (Sandbox Code Playgroud) 我正在使用scrapely从一些HTML中提取数据,但是我在提取项目列表时遇到了困难.
该scrapely GitHub的项目仅描述一个简单的例子:
from scrapely import Scraper
s = Scraper()
s.train(url, data)
s.scrape(another_url)
Run Code Online (Sandbox Code Playgroud)
例如,如果您尝试按照描述提取数据,这很好:
用法(API)
Scrapely有一个强大的API,包括可以在外部编辑的模板格式,您可以使用它来构建非常强大的scraper.
以下部分是最简单的可能用法的快速示例,您可以在Python shell中运行.
但是,如果您发现了类似的内容,我不确定如何提取数据
Ingredientes
- 50 gr de hojas de albahaca
- 4 cucharadas (60 ml) de piñones
- 2 - 4 dientes de ajo
- 120 ml (1/2 vaso) de aceite de oliva virgen extra
- 115 gr de queso parmesano recién rallado
- 25 gr de queso pecorino recién rallado ( o queso de leche de oveja curado)
Run Code Online (Sandbox Code Playgroud)
我知道我不能通过使用xpath或css选择器来提取它,但我更感兴趣的是使用可以为类似页面提取数据的解析器.
python ×8
matplotlib ×4
java ×2
numpy ×2
eclipse ×1
latex ×1
pca ×1
plot ×1
python-2.7 ×1
python-3.x ×1
scikit-learn ×1
scrapely ×1
sympy ×1
tex ×1
wireshark ×1