将字段添加到结构化numpy数组(3)

时间:2014-01-28 18:33:31

标签: python arrays numpy

已多次询问和回答(例如herehere)。显然这个功能已经在numpy 1.6.1中移动了。不再有numpy.lib.recfunctions。虽然我可以按照以前的帖子中的说明实现我自己的,但我真的而不是!

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

3 个答案:

答案 0 :(得分:3)

根据git historynumpy.lib.recfunctions并没有消失。

我会检查您的numpy安装,并可能将其升级到更新的版本。

答案 1 :(得分:1)

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

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']
>>>

答案 2 :(得分:0)

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

import matplotlib.mlab as mlab
mlab.rec_append_fields(recarray, names, data)
相关问题