NetworkX: AtlasView object
Error: โAtlasViewโ object does not support item assignment
networkx๋ก ์ฝ๋ฉ์ ํ๋ค๋ณด๋ฉด ์ข ์ข ๋จ๋ ์๋ฌ ์ค์์ ๋ค์์ ์๋ฌ๊ฐ ์์ต๋๋ค.
TypeError: 'AtlasView' object does not support item assignment
- ์๋ฌ ์ฝ๋๋ฅผ ๊ทธ๋๋ก ํด์ํ์๋ฉด โAtlasView ์ค๋ธ์ ํธ๋ item assignment๋ฅผ ์ด์ฉํ์ง ์๋๋คโ๋ผ๋ ๋ง์ด์ฃ .
What is AtlasView object?
- AtlasView๋ โdictionary of dictionary๋ก ๋์ด ์๋ Read-only ๊ตฌ์กฐโ๋ฅผ ๋งํฉ๋๋ค. networkx์์ node, edge๋ฅผ ์ ๊ทผํ ๋, dictionary์ฒ๋ผ
[]๋ก ์ ๊ทผํ๋ ๊ฒ์ AtlasView๋ผ๊ณ ๋งํ์ฃ . - ์ฆ, ์์์ ๋งํ error code๊ฐ ๋ด๋ค๋ ๊ฒ์ Read-only์ ๋ํด์ item assignment๋ฅผ ํ๋ค๋ ๋ง์ด์ฃ .
- ์ ์๋ฌ๋ ๊ฐ๋ น ๋ค์๊ณผ ๊ฐ์ด
nx.Graph์ ๋ํด์[]๋ก ๋ฐ๋ก ์ ๊ทผํ๋ ๊ฒฝ์ฐ ์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
G[0]['weight']=10
- ๋ฐ๋ผ์, ์์ฒ๋ผ ์ฒ๋ฆฌํ์ง ์๊ณ , ์๋์ฒ๋ผ ๋ณ๊ฒฝํด์ฃผ๋ฉด ํด๊ฒฐ๋ฉ๋๋ค.
G.nodes[0]['weight']=10
raw code
import networkx as nx
"""
What is Atlas view object
when, why happen?
TypeError: 'AtlasView' object does not support item assignment
"""
N = 6
p = 0.5
G = nx.fast_gnp_random_graph(N, p)
print(G.edges(data=True))
# ์๋์ ๊ฐ์ด Graph์ ๋ํด์ dictionary์ฒ๋ผ ์ ๊ทผํ์ฌ ๊ฐ์ ํ ๋นํ๋ ๊ฒฝ์ฐ, ์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
try:
G[0]['weight']=10
#G.nodes[0]['weight'] = 10 #์ด๋ ๊ฒ
print(G.nodes(data=True))
except Exception as e:
print("SOMETHING WRONG")
print("== error message")
print(e)
print("=="*20)
GitHub์์ ์ด ๊ธ์ ๋งํฌ๋ค์ด ์๋ณธ ๋ณด๊ธฐ & ์์ ์ ์src/content/posts/2020-01-28-nx_atlasviewobject
๐ ์ฐ๊ด ์ง์ ํ๋ธ:๐ python-libs ์นดํ
๊ณ ๋ฆฌ๐ธ NetworkX ์ปค๋ฆฌํ๋ผ#python#python-libs#networkx
๐กRELATED ARTICLES ยท ํจ๊ป ์ฝ์ผ๋ฉด ์ข์ ์ฐ๊ด ํฌ์คํธ
python-libs
NetworkX: second order centrality
์ฝ์ด๋ณด๊ธฐ→
python-libs
Networkx์์ node ํฉ์น๊ธฐ(MERGE node)
์ฝ์ด๋ณด๊ธฐ→
python-libs
ํ๊ตญ ํํฉ์ฌ ํผ์ณ๋ง ๋คํธ์ํฌ ๋ถ์ - 2ํธ - Data Collection Wisely
์ฝ์ด๋ณด๊ธฐ→
python-libs
ํ๊ตญ ํํฉ์ฌ ํผ์ณ๋ง ๋คํธ์ํฌ ๋ถ์ - 3ํธ - Data Analysis
์ฝ์ด๋ณด๊ธฐ→