astropy/astropy — pull request #2251 by mhvk (2014-03-28 03:41:13+00:00)
Title: Implement Quantity.flat, so that it always returns Quantity

Currently, `q.flat` does not work: if iterating over it, or getting a single item, it returns a float:
```
import astropy.units as u
q = u.Quantity([1., 2., 3.], 'm')
q.flat[:2]
# --> this is fine
q.flat[0]
# 1.0 --> this is not
for _q in q.flat: print(_q)
# 1.0
# 2.0
# 3.0 --> not good either
```
As `.flat` is used extensively in `MaskedArray`, this is needed eventually...

This PR fixes this by constructing a `QuantityIterator` class, which is used when the `flat` property is accessed. This procedure is inspired by that used in `MaskedArray`; if anybody has an idea how better to do this, most welcome...