pythonnumpymultidimensional-arraypython-xarray

What's the difference between Numpy's Structured arrays vs xarray (xray)?


What's the difference between Numpy Structured Arrays named fields vs xarray (xray) N-D labeled arrays ?


Solution

  • From the numpy docs on structured arrays:

    Structured datatypes [i.e. structured numpy arrays] are designed to be able to mimic ‘structs’ in the C language, and share a similar memory layout. They are meant for interfacing with C code and for low-level manipulation of structured buffers, for example for interpreting binary blobs. For these purposes they support specialized features such as subarrays, nested datatypes, and unions, and allow control over the memory layout of the structure.

    Users looking to manipulate tabular data, such as stored in csv files, may find other pydata projects more suitable, such as xarray, pandas, or DataArray. These provide a high-level interface for tabular data analysis and are better optimized for that use. For instance, the C-struct-like memory layout of structured arrays in numpy can lead to poor cache behavior in comparison.