PythonをJupyter notebook 6.3.0で使っています。networkxモジュールを使っており、
G = nx.Graph() for i in data: G.add_edge(i[3], i[5]) #Gを可視化 nx.draw(G, pos = nx.spring_layout(G)) plt.show()
を実行したところ、下のエラーが出てtuple index out of rangeは次の例外が直接の原因であると言われました。index自体は0から数えてi[3]とi[5]にしているため問題はないはずです。
IndexError Traceback (most recent call last) /opt/anaconda3/lib/python3.8/site-packages/networkx/utils/decorators.py in _random_state(func, *args, **kwargs) 395 try: --> 396 random_state_arg = args[random_state_index] 397 except TypeError as e: IndexError: tuple index out of range The above exception was the direct cause of the following exception: NetworkXError Traceback (most recent call last) <ipython-input-4-80ec21bc5569> in <module> 7 8 #Gを可視化 ----> 9 nx.draw(G, pos = nx.spring_layout(G)) 10 plt.show() /opt/anaconda3/lib/python3.8/site-packages/decorator.py in fun(*args, **kw) 229 if not kwsyntax: 230 args, kw = fix(args, kw, sig) --> 231 return caller(func, *(extras + args), **kw) 232 fun.__name__ = func.__name__ 233 fun.__doc__ = func.__doc__ /opt/anaconda3/lib/python3.8/site-packages/networkx/utils/decorators.py in _random_state(func, *args, **kwargs) 398 raise nx.NetworkXError("random_state_index must be an integer") from e 399 except IndexError as e: --> 400 raise nx.NetworkXError("random_state_index is incorrect") from e 401 402 # Create a numpy.random.RandomState instance NetworkXError: random_state_index is incorrect
そこでこのリンクにある通り、decoratorをアップデートしようと思い、Jupyter notebookで
pip install decorator == 5.1.1
を実行しました(5.1.1がdecoratorの最新バージョンです)。
しかし
zsh:1: = not found Note: you may need to restart the kernel to use updated packages.
と出てきてしまい、commandが(?)見つからないようです。kernelを再起動して、conda listでdecoratorのバージョンを確認しても5.0.6のままです。
どのようにすれば"NetworkXError: random_state_index is incorrect"を解決できるでしょうか。よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/30 12:43