[Numpy-discussion] [SciPy-Dev] NumPy/SciPy participation in GSoC 2013
Tue Apr 2 14:10:02 CDT 2013
On Tue, Apr 2, 2013 at 8:12 PM, Ralf Gommers <email@example.com> wrote:
> On Mon, Apr 1, 2013 at 2:27 PM, Todd <firstname.lastname@example.org> wrote:
>> There were a number of other ideas in this thread:
> Thanks Todd. Your idea 5 is pretty much what Nathaniel just detailed out,
> it's on the ideas page now. That should enable idea 1 as well. The other
> idea that got some positive feedback was 3:
> If you or someone else could make that a little more concrete, we can put
> that up.
With structured arrays, you can access them by name (key) in a manner
identical to dictionaries:
y = x['f']
It also has a method for accessing the list of names (keys):
This should be maintained for backwards-compatibility, but these methods
should also be added:
x.keys -- returns a list of field names
x.values -- returns a list of views into the array, one for each structure
x.items -- returns a list of tuple containing name/structure pairs (the
structures being a views)
x.iterkeys/itervalues/iteritems -- returns an iterable over the
corresponding objects (should not be available in python 3)
x.viewkeys/viewvalues/viewitems -- the same as the corresponding item,
since they always return views (should not be available in python 3)
x.has_key -- tests if a field name is present (should not be available in
python 3, should use "key in x.keys()")
x.get -- get a field by name, returning a default array (an empty array by
default) if not present
x.update -- copy values into the matching key from another structured
array, a dict, or list of key/value tuples. Unlike dicts this will only
work for keys that are already present.
Documentation should probably be updated to have these as the default ways
of interacting with structured arrays, with the old methods deprecated.
"Names" should also probably be renamed "keys" for compatibility with dicts.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion