[Numpy-discussion] ragged array implimentation
Jeff Whitaker
jswhit at fastmail.fm
Mon Mar 7 12:37:03 EST 2011
On 3/7/11 10:28 AM, Christopher Barker wrote:
> Hi folks,
>
> I'm setting out to write some code to access and work with ragged arrays
> stored in netcdf files. It dawned on me that ragged arrays are not all
> that uncommon, so I'm wondering if any of you have any code you've
> developed that I could learn-from borrow from, etc.
>
> note that when I say a "ragged array", I mean a set of data where the
> each row could be a different arbitrary length:
>
> 1, 2, 3, 4
> 5, 6
> 7, 8, 9, 10, 11, 12
> 13, 14, 15
> ...
>
> In my case, these will only be 2-d, though I suppose one could have a
> n-d version where the last dimension was ragged (or any dimension, I
> suppose, though I'm having trouble wrapping my brain around what that
> would look like...
>
> I'm not getting more specific about what I think the API should look
> like -- that is part of what I'm looking for suggestions, previous
> implementations, etc for.
>
> Is there any "standard" way to work with such data?
>
> -Chris
>
Chris: The netcdf4-python modules reads netcdf vlen arrays and returns
numpy object arrays, where the elements of the object arrays are
themselves 1d numpy arrays. I don't think there is any other way to do
it. In your example, the 'ragged' array would be a 1d numpy array with
dtype='O', and the individual elements would be 1d numpy arrays with
dtype=int. Of course, these arrays are very awkward to deal with and
operations will be slow.
-Jeff
--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker at noaa.gov
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
More information about the NumPy-Discussion
mailing list