我这样做的原因是因为我试图将窗口设置在屏幕的中心.我正在使用网格不打包,我已阅读有关使用wm grid但不了解如何设置它.我也不明白为什么. cget -width要回来0我认为格栅应该在没有给出选项时设置大小?
set width [. cget -width]
set height [. cget -height]
puts $height
puts $width
set x [expr { ( [winfo vrootwidth .] - $width ) / 2 }]
set y [expr { ( [winfo vrootheight .] - $height ) / 2 }]
wm title . "a3q2"
wm geometry . ${width}x${height}+${x}+${y}
Run Code Online (Sandbox Code Playgroud)
这次我做错了什么?PS作业我不只是想要一个代码发布.谢谢
假设C引用一组容器{c1,c2,c3....cn},其中每个容器包含一组有限的整数{i1,i2,i3...im}.此外,假设整数可能存在于多个容器中.给定一组有限的整数S {s1,s2,s3...sz},找到C包含所有整数的最小子集的大小S.
请注意,可能有数千个容器,每个容器有数百个整数.因此,蛮力很难解决这个问题.
我尝试使用Greedy算法解决问题.也就是说,每次我选择集合中整数最多的容器时S,我都失败了!
有谁能建议这个问题的快速算法?
我正在学习Python.一本关于Python 3的书说以下代码应该可以正常工作:
def funky():
print(myvar)
myvar = 20
print(myvar)
myvar = 10
funky()
Run Code Online (Sandbox Code Playgroud)
但是当我在Python 3.3中运行它时,我得到了
UnboundLocalError: local variable 'myvar' referenced before assignment
Run Code Online (Sandbox Code Playgroud)
错误.我的理解是,首先print(myvar)在funky应该是10,因为它是一个全局变量.第二个print(myvar)应该是20,因为本地myvar被定义为20.这里发生了什么?请帮忙澄清一下.
我希望使用具有常数因子的幂律来拟合我的x和y数据.我的幂律模型是y(r)= F0 + F*(r)**alpha其中F0是常数.我的代码是,
x = [0.015000000000000001, 0.024999999999999998, 0.034999999999999996, 0.044999999999999998, 0.055, 0.065000000000000002, 0.075000000000000011, 0.085000000000000006, 0.094999999999999987, 0.125, 0.17500000000000002, 0.22500000000000003, 0.27500000000000002]
y= [5.6283727993522774, 4.6240796612752799, 3.7366642904247769, 3.0668203445969828, 2.5751865553847577, 2.0815063796430979, 1.7152655187581032, 1.4686235817532258, 1.2501921057958358, 0.80178306738561222, 0.43372429238424598, 0.26012305284446235, 0.19396186239328625]
def func(x,m,c,c0):
return c0 + x**m * c
coeff,var=curve_fit(func,x,y)
print coeff
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/scipy/optimize/minpack.py", line 511, in curve_fit
raise RuntimeError(msg)
RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 800.
Run Code Online (Sandbox Code Playgroud)
然后我改变了maxfev = …
mat <- matrix(c(1,2,3,4,5,6,7,8,9), ncol=3)
mat[1:2, 1:2]
Run Code Online (Sandbox Code Playgroud)
返回新的matrix(c(1,2,4,5), ncol=2).
无论如何要访问矩阵元素,如情节的x,y位置?
一些function(mat, 1:2, 1:2)回报c(1,5)因为mat[1,1]并且mat[2,2]是1.5.
一些function(mat, c(1,1,2), c(2,1,1)回报
c(4, 1, 2)
Run Code Online (Sandbox Code Playgroud)
因为mat[1,2], mat[1,1], mat[2,1]是4,1,2.
我正在搞乱局部和全局命名空间,我发现了一些奇怪的行为.如果我这样做......
len(globals().keys())
len(locals().keys())
Run Code Online (Sandbox Code Playgroud)
我得到两个不同的结果,首先我得到344然后我得到346.因此,出于好奇心,我想知道哪些键在我的本地但不在我的全局,所以我这样做.
[key for key in local().keys() if key not in globals().keys()]
Run Code Online (Sandbox Code Playgroud)
而bam,没有,返回一个空列表.
想想也许我的代码有问题我试试这个.
g = [1,2,3,4]
l = [1,2,3,4,5,6]
[key for key in l if key not in g]
Run Code Online (Sandbox Code Playgroud)
并按预期返回 [5,6]
那么,Python无法区分locals()和globals()的键的原因是什么.
它locals() == globals()与副作用有关吗?
非常感谢.
我正在编写一个内部包含多个函数的函数(一个使用插入符包训练和测试多个模型的包装器)。
问题是,有时我想使用默认参数,有时我想指定我自己的参数。就我而言,有时我想修改tuneGrid,有时我想使用默认网格。我不能使用省略号(...)来传递这个参数,因为每个模型都需要一个单独的网格。
如何在函数参数中包含 if 语句?例如,
family = NULL
y <- rnorm(1000); x <- rnorm(1000)
glm(formula=y~x, if(!is.null(family)){family=family}, data=data.frame(x=x, y=y))
Run Code Online (Sandbox Code Playgroud)
由于多种原因,这不起作用,但我希望您能理解。我试图使用类似的东西作为第二个参数来解释逗号:
noquote( ifelse( !is.null(family), paste0(noquote("family="), family, "(),") ) )
Run Code Online (Sandbox Code Playgroud)
如果您有任何想法,请告诉我。
我Crypt::encrypt用来加密我的数据并提供给Javascript代码。如何解密Javascript中的数据?
家庭作业的代码有问题.基本上我要做的就是接受一个对象列表并将它们传递给我的fire方法.
def fire(self,targets):
i = 0
for i in targets:
x,y = targets[i].position
tx,ty = self.position
d = getDist(targets[i].position, self.position)
Run Code Online (Sandbox Code Playgroud)
每当我调用fire方法并传入对象时,它就会指向第17行,即x,y = targets[i].position行,并说"TypeError:list indices必须是整数,而不是Bomber"
轰炸机是班级的名称.我像这样调用fire方法:
bOne.fire([bTwo, tOne, tTwo, tThree])
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢.
当我将输入设为'x'时,compVal将值设为-1.我期待0,因为两个值都相同.请有人解释原因.
char ch = getchar();
int compVal = strcmp("x", &ch);
Run Code Online (Sandbox Code Playgroud) python ×4
function ×2
r ×2
algorithm ×1
arguments ×1
c ×1
cryptojs ×1
javascript ×1
laravel ×1
list ×1
matrix ×1
namespaces ×1
null ×1
php ×1
python-3.x ×1
scipy ×1
tcl ×1
tk-toolkit ×1