Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

python - Adding a field to a structured numpy array (2)

I know there was already a question about this topic (cleanest way to add a field to a structured numpy array), see

Adding a field to a structured numpy array

but I have a question about the answer given there ...

If you're using numpy 1.3, there's also numpy.lib.recfunctions.append_fields()

I still have numpy 1.3, but it doesn't recognise this function, and I also didn't find anything about it in the documentation of numpy. What happened with the function? Is there another function that can do the same?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

http://projects.scipy.org/numpy/browser/branches/1.3.x/numpy/lib/recfunctions.py?rev=8229

did you import?

from numpy.lib import recfunctions

recfunctions.append_fields(*your_args)  # base, names, data, ...

Seems like everything is working:

Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.3.0'
>>> from numpy.lib.recfunctions import append_fields
>>> append_fields
<function append_fields at 0x9e3e80c>
>>> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...