python输出para关键词占比_字符串格式问题(paratheses vs underline)

遇到genfromtxt问题时,首先要打印shape和{}。

为什么必须在col_headers = [('VW_3_Avg','

是因为文件头中有这些名字吗?在

如果您提供自己的dtype并使用skip_header,那么文件中的内容无关紧要。重要的是dtype中的字段名,而不是文件中的字段名。在

{我们可以在cd3>中找到什么字符。作为Python变量名的字段名当然可以。我并不惊讶()会被禁止或有问题,尽管我还没有测试过。在

实际上,'Lvl_Max(1)'可以作为数据类型字段名:In [235]: col_headers = [('VW_3_Avg','

In [236]: A=np.zeros((3,),dtype=col_headers)

In [237]: A

Out[237]:

array([(0.0, 0.0), (0.0, 0.0), (0.0, 0.0)],

dtype=[('VW_3_Avg', '

In [238]: A['Lvl_Max(1)']

Out[238]: array([ 0., 0., 0.])

从一开始,您应该做的是向我们展示datafile.shape和{}。这些genfromtxt问题的90%源于对函数返回的误解。在

让我们用以下数据类型尝试一个简单的文件读取:

^{pr2}$

看看dtype。genfromtxt已经剥离了{}。看起来genfromtxt“清理”了字段名,毫无疑问,因为文本文件上的名称可能有各种有趣的东西。在

来自genfromtxt文档:Numpy arrays with a structured dtype can also be viewed as recarray, where a field can be accessed as if it were an attribute. For that reason, we may need to make sure that the field name doesn’t contain any space or invalid character, or that it does not correspond to the name of a standard attribute (like size or shape), which would confuse the interpreter.

genfromtxt接受一个deletechars参数,该参数应该允许您控制从字段名中删除哪些字符。但它的应用程序不一致。在In [282]: np.genfromtxt(txt.splitlines(),names=np.dtype(col_headers).names,deletechars=set(b' '),dtype=None)

Out[282]:

array([(1, 2), (3, 4), (5, 6)],

dtype=[('VW_3_Avg', '

In [283]: np.genfromtxt(txt.splitlines(),names=np.dtype(col_headers).names,deletechars=set(b' '))

Out[283]:

array([(1.0, 2.0), (3.0, 4.0), (5.0, 6.0)],

dtype=[('VW_3_Avg', '

此操作需要dtype=None。在

默认设置为“大”:defaultdeletechars = set("""~!@#$%^&*()-=+~\|]}[{';: /?.>,

问题是deletechars被传递给validator:validate_names = NameValidator(...

deletechars=deletechars,...)

它用于清除头和names参数中的名称。但随后名称(和数据类型)被传递dtype = easy_dtype(dtype, defaultfmt=defaultfmt, names=names)

没有deletechars参数。这个问题大约在一年前被解决,https://github.com/numpy/numpy/pull/4649,因此可能会在新(est)版本中修复。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值