繁体   English   中英

向结构化的numpy数组添加字段(3)

[英]Adding a field to a structured numpy array (3)

这个问题已经被询问和回答了好几次(例如, 这里这里 )。 显然,该功能已在numpy 1.6.1中移动。 没有更多的numpy.lib.recfunctions 虽然我可以按照以前的帖子中的说明实现自己的功能,但我真的不愿意!

有人可以告诉我该功能的路径吗? 已经recfunctions作为一个整体被移动或合并到另一个库?

根据git的历史记录numpy.lib.recfunctions并没有消失。

我会检查您的numpy安装情况,也许将其升级到新版本。

这对我有用...但是我不清楚为什么。 也许有人可以解释:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.6.1'
>>> numpy.lib
<module 'numpy.lib' from 'C:\Python27\ArcGIS10.1\lib\site-packages\numpy\lib\__init__.pyc'>
>>> numpy.lib.recfunctions    #### <- why does this not work?
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'recfunctions'
>>> import numpy.lib.recfunctions
>>> dir(numpy.lib.recfunctions)
['MaskedArray', 'MaskedRecords', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_check_fill_value', '_fix_defaults', '_fix_output','_is_string_like', '_izip_fields', '_izip_fields_flat', 'append_fields', 'drop_fields', 'find_duplicates', 'flatten_descr', 'get_fieldstructure', 'get_names', 'get_names_flat', 'itertools', 'izip_records', 'join_by', 'ma', 'merge_arrays', 'ndarray', 'np', 'rec_append_fields', 'rec_drop_fields', 'rec_join', 'recarray', 'recursive_fill_fields', 'rename_fields', 'stack_arrays', 'sys', 'zip_descr']
>>>

我发现将数组追加到记录数组中,使用mlab recfunctions是可以的,但是numpy recfunctions是不可以的。

import matplotlib.mlab as mlab
mlab.rec_append_fields(recarray, names, data)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM