草庐IT

integer-programming

全部标签

python - Mercurial 预提交 Hook : How to hook to python program in current directory?

我正在尝试创建一个MercurialHook,该Hook在提交被推送到主存储库时运行。我创建了一个python脚本,如下所示:#commit.pyfrommercurialimportui,hgfrommercurial.i18nimportgettextas_defgetV1ID(ui,repo,**kwargs):ui.write("Thehookworks!!!")v1id=ui.prompt('EntertheVersionOneID')ui.write('VersionOneID:'+v1id)对于每个分支,此commit.py都是重复的,因为它包含在代码被推送到主存储库之前

python - 将 "integer" float 转换为 int 总是会返回最接近的整数吗?

我通过将两个数字相除得到一个float。我知道数字是可以整除的,所以我总是有一个整数,只是它是浮点型的。但是,我需要一个实际的int类型。我知道int()会去掉小数点(即四舍五入)。我担心因为花车不准确,如果我这样做,例如int(12./3)或int(round(12./3))它可能最终为3而不是4,因为4的浮点表示可能是3.9999999593519561(不是,只是一个例子)这会发生吗?我能确保它不会发生吗?(我问是因为在reshape一个numpy数组时,我收到一条警告说形状必须是整数,而不是float。) 最佳答案 将flo

python 错误 "list indices must be integers",它们是整数

我有一个问题。我有一个包含31个元素的数组,称为颜色。我还有另一个数组,整数在0到31之间变化,这称为c。我想生成一个新数组,其中c中的值现在是颜色中的相应值。我写:newarray=colors[c]但得到错误消息“listindicesmustbeintegers”但c是一个整数数组。我是python的新手,没有时间学习教程,因为我只需要它来完成特定的绘图任务。谁能帮帮我?谢谢 最佳答案 整数数组!=整数列表索引必须是整数-你已经给出了一个整数列表。你可能想要一个列表理解:newarray=[colors[i]foriinc]编

python - float.as_integer_ratio() 的实现限制

近日,有记者提到float.as_integer_ratio(),Python2.6中的新增功能,指出典型的浮点实现本质上是实数的有理逼近。出于好奇,我不得不尝试π:>>>float.as_integer_ratio(math.pi);(884279719003555L,281474976710656L)我有点惊讶没有看到更多accurate结果归因于Arima,:(428224593349304L,136308121570117L)例如,这段代码:#!/usr/bin/envpythonfromdecimalimport*getcontext().prec=36print"pytho

python - 可见弃用警告 : using a non-integer number instead of an integer will result in an error in the future

当运行涉及以下函数的python程序时,image[x,y]=0给出以下错误消息。这是什么意思,如何解决?谢谢。警告VisibleDeprecationWarning:usinganon-integernumberinsteadofanintegerwillresultinanerrorinthefutureimage[x,y]=0Illegalinstruction(coredumped)代码defcreate_image_and_label(nx,ny):x=np.floor(np.random.rand(1)[0]*nx)y=np.floor(np.random.rand(1)[

python - TypeError : list indices must be integers, 不是 str Python

list[s]是一个字符串。为什么这不起作用?出现如下错误:TypeError:listindicesmustbeintegers,notstrlist=['abc','def']map_list=[]forsinlist:t=(list[s],1)map_list.append(t) 最佳答案 当你遍历一个列表时,循环变量接收实际的列表元素,而不是它们的索引。因此,在您的示例中s是一个字符串(第一个abc,然后是def)。看起来您要做的基本上是这样的:orig_list=['abc','def']map_list=[(el,1)f

Python 溢出错误 : cannot fit 'long' into an index=sized integer

我想使用我在网上找到并稍作修改的算法生成两个非常大的素数。我在第5行收到此错误:PythonOverflowError:cannotfit'long'intoanindex=sizedinteger我的代码:importmathdefatkin(end):ifend>1):ifnotsieve[i]:continueforjinrange((i*(i+3)如何解决我的错误?如果您知道生成大素数的更好方法,那也会有所帮助。 最佳答案 以下代码演示了您遇到的问题:importsysx=[True]*(sys.maxint+1)这会产生一

python - 使用 python 运行 bash 脚本 - TypeError : bufsize must be an integer

我正在尝试编写python文件,即python中的wxtractar文件。据我所知,subprocess是完成此任务的合适工具。我写了下面的代码:fromsubprocessimportcalldeftarfile(path):call(["tar"],path)if__name__=="__main__":tarfile("/root/tryit/output.tar")当输出为tar文件时,位于/root/tryit/。当我运行它时,我收到以下消息:TypeError:bufsizemustbeaninteger我可以通过这个工具使用tar命令吗? 最佳

python - (Python) 值错误 : Program dot not found in path

我有以下问题:我在xUbuntu操作系统上,我正在尝试在Flask应用程序中使用networkx,我有以下代码:.....importnetworkxasnx......#Creatingandinitializinggraphobjectwhichisnetworkxobjecthosts_graph=get_networkx_graph_object()#Variable'coord'wherethecoordinatesforeachnodewillbestoredcoord=nx.pygraphviz_layout(hosts_graph,prog='dot')最后一行是第41

python "TypeError: ' numpy.float6 4' object cannot be interpreted as an integer"

importnumpyasnpforiinrange(len(x)):if(np.floor(N[i]/2)==N[i]/2):forjinrange(N[i]/2):pxd[i,j]=x[i]-(delta*j)*np.sin(s[i]*np.pi/180)pyd[i,j]=y[i]-(delta*j)*np.cos(s[i]*np.pi/180)else:forjinrange((N[i]-1)/2):pxd[i,j]=x[i]-(delta*j)*np.sin(s[i]*np.pi/180)pyd[i,j]=y[i]-(delta*j)*np.cos(s[i]*np.pi/180