Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

126~131 줄 실행 오류 #2

Open
RachHus opened this issue Feb 2, 2023 · 2 comments
Open

126~131 줄 실행 오류 #2

RachHus opened this issue Feb 2, 2023 · 2 comments

Comments

@RachHus
Copy link

RachHus commented Feb 2, 2023

Cell In[12], line 26, in create_absence_points(presence, total_area, radius, count)
23 res_difference = total_area.overlay(presence_bfr, how='difference')
25 # 임의지점 생성 함수
---> 26 absence = random_points_in_gdf(res_difference, count)
27 absence['CLASS'] = 0
28 return absence

Cell In[12], line 40, in random_points_in_gdf(gdf, size, overestimate)
38 multipoint = multipoint.intersection(polygon)
39 samples = np.array(multipoint)
---> 40 points = samples[np.random.choice(len(samples), size)]
41 df = pd.DataFrame(points, columns=['lon', 'lat'])
42 return gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.lon, df.lat))

TypeError: len() of unsized object
제가 파이선을 제대로 사용해 본 경험이 없어서..예제 파일로 이제서야 돌려보고 있습니다. 126~131줄 실행하니 위와 같은 메세지가 뜨는데, sample에 들어가는 정보가 없는걸까요 아니면 길이를 알 수 없는 데이터가 들어가서 일까요..??? 전 코드 대로 실행했는데 어디서 잘못된 건지 잘 모르겠습니다. intersection하는 객체가 없어서 일까도 궁금하고요.

@osgeokr
Copy link
Owner

osgeokr commented Feb 3, 2023

안녕하세요? 아마도 len()이 오류를 유발한 것 같습니다.

points = samples[np.random.choice(len(samples), size)]

len(samples)를 samples.size로 변경 후 체크해 보시겠어요?

points = samples[np.random.choice(samples.size, size)]

@RachHus
Copy link
Author

RachHus commented Feb 3, 2023

말씀 해주신대로 변경했는데도 아래와 같은 오류가 떴습니다.

IndexError Traceback (most recent call last)
Cell In[25], line 1
----> 1 absence = random_points_in_gdf(res_difference, presence.shape[0],2)
2 absence['CLASS'] = 0

Cell In[14], line 12, in random_points_in_gdf(gdf, size, overestimate)
10 multipoint = multipoint.intersection(polygon)
11 samples = np.array(multipoint)
---> 12 points = samples[np.random.choice((samples.size), size)]
13 df = pd.DataFrame(points, columns=['lon', 'lat'])
14 return gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.lon, df.lat))

IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed

한 1시간 반동안 씨름하다가
len(samples)는 유지하고,
samples = np.array(multipoint)를
samples = np.array([p.coords[0] for p in multipoint.geoms]) 로 바꾸니 실행이 됐습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants