草庐IT

are_convertible

全部标签

python - 函数速度提升 : Convert ints to list of 32bit ints

我正在寻找我的功能的快速替代品。目标是根据任意长度的整数制作一个32位整数列表。长度在(value,bitlength)的元组中明确给出。这是异步接口(interface)的位分解过程的一部分,每个总线事务采用4个32位整数。所有整数都是无符号的、正数或零,长度可以在0到2000之间变化我的输入是这些元组的列表,输出应该是隐式32位长度的整数,位按顺序排列。不适合32的剩余位也应返回。input:[(0,128),(1,12),(0,32)]output:[0,0,0,0,0x100000],0,12我花了一两天时间用cProfile进行分析,并尝试不同的方法,但我似乎有点受困于一秒钟

python : overflow error long int too large to convert to float

我必须计算2的8635次方。我在计算2^8635时遇到了这个错误。关于如何在python中解决这个问题的任何建议。使用Decimal模块也没有帮助。math.exp(2**8635)Traceback(mostrecentcalllast):File"",line1,inlong(math.exp(2**8635))OverflowError:longinttoolargetoconverttofloat 最佳答案 您可以使用mpmath任意精度数学模块计算exp(2**8635):>>>frommpmathimportmp>>>m

python - ts.plot() 和 dataFrame.plot() 抛出错误 : "NameError: name ' _converter' is not defined"

运行数据框或系列的plot()方法时,python会抛出错误。错误的最后一行是NameError:name'_converter'isnotdefined我使用的是Python3.6,所有其他功能都按预期工作,所以不确定是什么原因造成的。下面是导致问题的代码示例,下面是导致的错误。importpandasaspdimportnumpyasnpimportmatplotlibimportmatplotlib.pyplotaspltts=pd.Series(np.random.randn(1000),index=pd.date_range('1/1/2000',periods=1000))

python - 使用 python 和 scikit-learn 的 DBSCAN : What exactly are the integer labes returned by make_blobs?

我正在尝试理解由scikit(http://scikit-learn.org/0.13/auto_examples/cluster/plot_dbscan.html)实现的DBSCAN算法的示例。我换了行X,labels_true=make_blobs(n_samples=750,centers=centers,cluster_std=0.4)使用X=my_own_data,因此我可以将自己的数据用于DBSCAN。现在,变量labels_true是make_blobs的第二个返回参数,用于计算结果的一些值,如下所示:print"Homogeneity:%0.3f"%metrics.ho

安卓 4.1 : How to check notifications are disabled for the application?

Android4.1为用户提供了一个复选框来禁用特定应用程序的通知。但是,作为开发人员,我们无法知道通知的调用是否有效。我确实需要检查当前应用程序是否禁用了通知,但我在API中找不到任何设置。有没有办法在代码中检查此设置? 最佳答案 你不能100%不能。在thisGoogleI/O2012video中询问并且新通知的项目负责人声明您不能。编辑2016年更新:现在可以查看了,如thisGoogleI/O2016video中所述.使用NotificationManagerCompat.areNotificationsEnabled(),

安卓 4.1 : How to check notifications are disabled for the application?

Android4.1为用户提供了一个复选框来禁用特定应用程序的通知。但是,作为开发人员,我们无法知道通知的调用是否有效。我确实需要检查当前应用程序是否禁用了通知,但我在API中找不到任何设置。有没有办法在代码中检查此设置? 最佳答案 你不能100%不能。在thisGoogleI/O2012video中询问并且新通知的项目负责人声明您不能。编辑2016年更新:现在可以查看了,如thisGoogleI/O2016video中所述.使用NotificationManagerCompat.areNotificationsEnabled(),

python - matplotlib 中的历史记录 : Bins are not centered and proportions not correct on the axis

看看这个例子:importmatplotlib.pyplotaspltl=[3,3,3,2,1,4,4,5,5,5,5,5,5,5,5,5]plt.hist(l,normed=True)plt.show()输出以图片形式发布。我有两个问题:a)为什么只有4和5bin以它的值为中心?其他人不应该也是这样吗?有什么技巧可以让它们居中吗?b)为什么bins没有按比例归一化?我希望所有bin的y值总和为1。请注意,我的真实示例在列表中包含更多值,但它们都是离散的。 最佳答案 您应该调整plt.hist函数的关键字参数。它们有很多,而且doc

python - Spark : Broadcast variables: It appears that you are attempting to reference SparkContext from a broadcast variable, Action ,或转换

ClassProdsTransformer:def__init__(self):self.products_lookup_hmap={}self.broadcast_products_lookup_map=Nonedefcreate_broadcast_variables(self):self.broadcast_products_lookup_map=sc.broadcast(self.products_lookup_hmap)defcreate_lookup_maps(self)://ThecodeherebuildsthehashmapthatmapsProd_IDtoanoth

python - pyspark : Convert DataFrame to RDD[string]

我想将pyspark.sql.dataframe.DataFrame转换为pyspark.rdd.RDD[String]我将DataFramedf转换为RDDdata:data=df.rddtype(data)##pyspark.rdd.RDD新的RDDdata包含Rowfirst=data.first()type(first)##pyspark.sql.types.Rowdata.first()Row(_c0=u'aaa',_c1=u'bbb',_c2=u'ccc',_c3=u'ddd')我想将Row转换为String列表,如下例所示:u'aaa',u'bbb',u'ccc',u'd

python - PostgreSQL 类型错误 : not all arguments converted during string formatting

我在链接到PostgreSQL数据库的psycopg2中执行查询。这是有问题的代码:withopen('dataFile.txt','r')asf:lines=f.readlines()newLines=[line[:-1]forlineinlines]curr=conn.cursor()lineString=','.join(newLines)curr.execute("SELECTfields.fieldkeyFROMfieldsLEFTJOINzoneONzone.fieldkey=fields.fieldkeyWHEREzone.zonekey=%s;",(newLines[0