generalize dict_to_array() for nD arrays