[Numpy-discussion] convert dictionary of arrays into single array
Wed Mar 16 09:30:29 CDT 2011
On 03/16/2011 08:56 AM, John Salvatier wrote:
> Loop through to build a list of arrays, then use vstack on the list.
> On Wed, Mar 16, 2011 at 1:36 AM, John <email@example.com
> <mailto:firstname.lastname@example.org>> wrote:
> I have a dictionary with structured arrays, keyed by integers 0...n.
> There are no other keys in the dictionary.
> What is the most efficient way to convert the dictionary of arrays to
> a single array?
> All the arrays have the same 'headings' and width, but different
> Is there something I can do that would be more efficient than looping
> through and using np.concatenate (vstack)?
Numpy does not permit a 'single' array of different shapes - ie a
Sure you could convert this into a structured array (you know n so you
can create an appropriate empty structured array and assign the array by
looping across the dict) but that is still not a 'single' array. You can
use a masked array where you masked the missing elements across your arrays.
Francesc Alted pointed out in the 'ragged array implimentation' thread
pytables does support this.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion