networkx/networkx — pull request #788 by dasmith (2012-11-02 17:10:13+00:00)
Title: Added utility function to convert dicts of numbers to numpy vector

I often use networkx for constructing a distance matrix:

```python
# distance matrix construction
import networkx as nx

G = nx.DiGraph()
G.add_edge('a', 'b')
G.add_edge('b', 'c')
G.add_edge('c', 'd')

lengths = nx.shortest_path_length(G)
# lengths => {'a': {'a': 0, 'c': 1, 'b': 1, 'e': 2}, 'c': {'c': 0, 'e': 1}, 'b': {'b': 0}, 'e': {'e': 0}}

dm = nx.utils.dict_to_numpy_array(lengths)
```

However, if you restrict your shortest paths to a single source, then `shortest_path_length` returns a dictionary of path lengths, not a dictionary of dictionaries. (If you supply a `target` and `source` parameter, it returns a single number, the path length).

```python
G = nx.DiGraph()
G.add_edge('a', 'b')
G.add_edge('b', 'c')
G.add_edge('c', 'd')

lengths = nx.shortest_path_length(G, source='a')
# lengths => {'a': 0, 'c': 1, 'b': 1, 'e': 2}
dm = nx.utils.dict_to_numpy_array(lengths) # => Attribute Error
```
will lead to an **AttributeError: 'int' object has no attribute 'keys'** on line 116 of `networkx/utils/misc.py`.

To accommodate this case, I created a `dict_to_numpy_vector` function, and modified the existing `dict_to_numpy_array` function to check for this special case and dispatch the new function when appropriate.