问题描述
将字段添加到结构化numpy数组的最干净方法是什么?可以破坏性地完成它,还是必须创建一个新的数组并在现有字段上进行复制?每个字段的内容是否连续存储在内存中,以便可以高效地进行复制?
What is the cleanest way to add a field to a structured numpy array? Can it be done destructively, or is it necessary to create a new array and copy over the existing fields? Are the contents of each field stored contiguously in memory so that such copying can be done efficiently?
推荐答案
如果您使用的是numpy 1.3,则还有numpy.lib.recfunctions.append_fields().
If you're using numpy 1.3, there's also numpy.lib.recfunctions.append_fields().
对于许多安装,您需要import numpy.lib.recfunctions
进行访问. import numpy
不允许看到numpy.lib.recfunctions
For many installations, you'll need to import numpy.lib.recfunctions
to access this. import numpy
will not allow one to see the numpy.lib.recfunctions
这篇关于将字段添加到结构化的numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!