[Numpy-discussion] convert dictionary of arrays into single array

John washakie@gmail....
Wed Mar 16 17:02:46 CDT 2011


Yes, stacking is fine, and looping per John's suggestion is what I've
done, I was just wondering if there was possibly a more 'pythonic' or
more importantly efficient way than the loop.

Thanks,
john

On Wed, Mar 16, 2011 at 3:38 PM, John Salvatier
<jsalvati@u.washington.edu> wrote:
> I think he wants to stack them (same widths) so stacking them should be
> fine.
>
> On Wed, Mar 16, 2011 at 7:30 AM, Bruce Southey <bsouthey@gmail.com> wrote:
>>
>> 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 <washakie@gmail.com> wrote:
>>>
>>> Hello,
>>>
>>> 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 lengths.
>>>
>>> Is there something I can do that would be more efficient than looping
>>> through and using np.concatenate (vstack)?
>>> --john
>>> _______________________________________________
>>
>> Numpy does not permit a 'single' array of different shapes - ie a 'ragged
>> array'.
>> 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
>> (http://mail.scipy.org/pipermail/numpy-discussion/2011-March/055219.html)
>> that pytables does support this.
>>
>> Bruce
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>



-- 
Configuration
``````````````````````````
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Python 2.6
PIL 1.1.6
Mailman 2.1.9
Postfix 2.4.5
Procmail v3.22 2001/09/10
Basemap: 1.0
Matplotlib: 1.0.0


More information about the NumPy-Discussion mailing list