草庐IT

DATA_EVAL

全部标签

python - OpenCV cv2.fillPoly 与 cv2.fillConvexPoly : expected data type for array of polygon vertices?

我有以下代码:importcv2importnumpyar=numpy.zeros((10,10))triangle=numpy.array([[1,3],[4,8],[1,9]],numpy.int32)如果我像这样使用cv2.fillConvexPoly:cv2.fillConvexPoly(ar,triangle,1)那么结果是符合预期的。但是,如果我尝试:cv2.fillPoly(ar,triangle,1)然后我得到一个失败的断言。如果我为cv2.fillConvexPoly使用没有dtypenumpy.int32的numpy数组,这似乎与失败的断言相同。cv2.fillPo

python - 在 python 3 中的函数中创建动态命名变量/理解 python 3 中的 exec/eval/locals

首先,我要说的是,我阅读了很多关于创建动态命名变量的类似主题的帖子,但它们大多与Python2相关,或者它们假定您正在使用类。是的,我读了BehaviorofexecfunctioninPython2andPython3.我也知道创建动态命名的变量在99%的时间里是一个坏主意,字典是获得的方式,但我只想知道它是否仍然可能以及exec和locals在python中的工作方式3.我想展示一些示例代码来说明我的问题(fibonacci计算斐波那契数,ListOfLetters提供["A","B",...]):deffunctionname():forindex,buchstabeinenum

python - 如何按特定值过滤 tf.data.Dataset?

我通过读取TFRecords创建了一个数据集,我映射了值,我想过滤数据集的特定值,但由于结果是一个带有张量的字典,我无法获得张量的实际值或用tf.cond()/tf.equal检查它。我该怎么做?defmapping_func(serialized_example):feature={'label':tf.FixedLenFeature([1],tf.string)}features=tf.parse_single_example(serialized_example,features=feature)returnfeaturesdeffilter_func(features):#th

Python 设置.py : ask for configuration data during setup

我用PIP打包我的Python应用程序,提供一个setup.py。在安装过程中,我想向用户询问几个值(用户名,其他配置值),然后将这些值保存在用户目录中存储的应用程序配置文件中。在安装过程中是否有特殊的PIP/distutils方式来询问这些配置值?或者我应该只使用input来询问用户,就像这样:#!/usr/bin/envpythonfromdistutils.coreimportsetupcfg['name']=input("Pleaseyourusername:")cfg.save()setup(name='appname',version='1.0',description='

PHP xmlrpc 客户端和 Python 2.5 xmlrpc 服务器 : incomplete data and Connection reset by peer error

我有一个运行Python的XMLRPC服务器。它作为SimpleXMLRPCServer类的实例实现。fromSimpleXMLRPCServerimportSimpleXMLRPCServerfromSimpleXMLRPCServerimportSimpleXMLRPCRequestHandlerclassMyClass:defgetGeneExtraInfo(self,genome,infoType,elements):print'DEBUG:\ngenome:%s\ninfoType:%s,elements%s'%(genome,infoType,elements)return

python - Django : loaddata to update data

我有一个fixtureseed_data.json,上面有我的初始数据。有时我将新数据添加到这个装置中并重新加载它,这会正确更新我的数据。但是,我现在想从中删除一些数据。所以我修改了我的seed_data.json,例如,我有类似的东西:{"fields":{"name":"Field0"},"model":"catalog.product","pk":1},{"fields":{"name":"Field1"},"model":"catalog.product","pk":2},{"fields":{"name":"Field2"},"model":"catalog.product"

python - TensorFlow tf.data.Dataset 和分桶

对于LSTM网络,我看到分桶有很大的改进。我遇到了bucketingsectionintheTensorFlowdocs哪个(tf.contrib)。虽然在我的网络中,我使用的是tf.data.DatasetAPI,特别是我正在使用TFRecords,所以我的输入管道看起来像这样dataset=tf.data.TFRecordDataset(TFRECORDS_PATH)dataset=dataset.map(_parse_function)dataset=dataset.map(_scale_function)dataset=dataset.shuffle(buffer_size=1

python - Pandas 系列出现 'Data must be 1-dimensional' 错误

我是pandas和numpy的新手。我正在运行一个简单的程序labels=['a','b','c','d','e']s=Series(randn(5),index=labels)print(s)出现以下错误s=Series(randn(5),index=labels)File"C:\Python27\lib\site-packages\pandas\core\series.py",line243,in__init__raise_cast_failure=True)File"C:\Python27\lib\site-packages\pandas\core\series.py",line

python - Django 表单中的隐藏字段不在 cleaned_data 中

我有这个表格:classCollaboratorForm(forms.Form):user=forms.CharField(label="Username",max_length=100)canvas=forms.IntegerField(widget=forms.HiddenInput)....defclean_user(self):user=self.cleaned_data['user']canvas=self.cleaned_data['canvas']在View中我只是调用ifform.is_valid():我得到错误:KeyErrorat/canvas/1/add-coll

python - 是否有 Python 等同于 Perl 的 __DATA__ 文件句柄?

在Perl中,我经常从脚本末尾的文件句柄__DATA__中读取数据:while(){chomp;say;}__DATA__line1line2我发现这比读取文件更快地测试代码等,因为这意味着我可以即时编辑其内容。来自doc:The__DATA__tokentellstheperlcompilerthattheperlcodeforcompilationisfinished.Everythingafterthe__DATA__tokenisavailableforreadingviathefilehandleFOOBAR::DATA,whereFOOBARisthenameofthecu