Repository: networkx/networkx

Issue:
edgelist in draw_network does not support arrays
Using numpy 1.18.2 and networkx 2.4, it is not possible to use a numpy array for the `edgelist` argument of [``draw_networkx``](https://networkx.github.io/documentation/stable/reference/generated/networkx.drawing.nx_pylab.draw_networkx.html).
It raises:
```
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```

I normally would not have opened an issue for that but I do not see the point of the current implementation, so in case it can be changed harmlessly to support numpy arrays, that might be a win-win.

The issue comes from lines 575-579 on 2.4 ([lines 640-647](https://github.com/networkx/networkx/blob/master/networkx/drawing/nx_pylab.py#L640) on master) that read:

```python
    if edgelist is None:
        edgelist = list(G.edges())

    if not edgelist or len(edgelist) == 0:  # no edges!
        return None
```

I am not sure what the combination of ``not edgelist`` and ``len(edgelist) == 0`` is for, here, so I would propose to change it to

```python
    if edgelist is None:
        edgelist = list(G.edges())
    elif len(edgelist) == 0:  # no edges!
        return None
```

which should still do the job for all valid inputs I can think of and would also work with numpy arrays.

**EDIT** if iterables should be supported, one could replace ``not edgelist`` by ``not isinstance(edgelist, Iterable)``


Discussion:
The ```if not edgelist``` part of that line is very old when that syntax was subtly different. The code is intended to work for lists, tuples, sets, frozensets and other containers (like numpy arrays). We assume they have a ```__len__``` feature.

I'm actually surprised that numpy changed the behavior of ```if a:``` It used to check whether ```len(a)!=0```.

In any case, this should be changed as per your suggestion!  Thanks!
OK, nice, I can make a PR if that helps.
Iterators do not need to be supported, if I understand correctly, then, right? I can just use the ``elif len(edgelist) == 0:``?
Yes, that is (I believe) the only change needed. 
It might be good to have a test to make sure that a numpy array works.

Resolving patch:
diff --git a/networkx/drawing/nx_pylab.py b/networkx/drawing/nx_pylab.py
--- a/networkx/drawing/nx_pylab.py
+++ b/networkx/drawing/nx_pylab.py
@@ -640,7 +640,7 @@ def draw_networkx_edges(
     if edgelist is None:
         edgelist = list(G.edges())
 
-    if not edgelist or len(edgelist) == 0:  # no edges!
+    if len(edgelist) == 0:  # no edges!
         if not G.is_directed() or not arrows:
             return LineCollection(None)
         else:


Test patch:
diff --git a/networkx/drawing/tests/test_pylab.py b/networkx/drawing/tests/test_pylab.py
--- a/networkx/drawing/tests/test_pylab.py
+++ b/networkx/drawing/tests/test_pylab.py
@@ -250,3 +250,8 @@ def test_alpha_iter(self):
     def test_error_invalid_kwds(self):
         with pytest.raises(ValueError, match="Received invalid argument"):
             nx.draw(self.G, foo="bar")
+
+    def test_np_edgelist(self):
+        # see issue #4129
+        np = pytest.importorskip("numpy")
+        nx.draw_networkx(self.G, edgelist=np.array([(0, 2), (0, 3)]))