numpy.histogram2d
나를 위해 2 배열에있는 데이터를 십자가에 데이터를 보려고하는 중이 야. 전에이 기능을 사용 해본 적이 없으며 수정 방법을 모르는 오류가 발생합니다. 다음과 같은 오류에문제가 numpy.histogram2d와
import numpy as np
import random
zones = np.zeros((20,30), int)
values = np.zeros((20,30), int)
for i in range(20):
for j in range(30):
values[i,j] = random.randint(0,10)
zones[:8,:15] = 100
zones[8:,:15] = 101
zones[:8,15:] = 102
zones[8:,15:] = 103
np.histogram2d(zones,values)
이 코드 결과 :
여기---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-18-53447df32000> in <module>()
----> 1 np.histogram2d(zones,values)
C:\Python27\ArcGISx6410.2\lib\site-packages\numpy\lib\twodim_base.pyc in histogram2d(x, y, bins, range, normed, weights)
613 xedges = yedges = asarray(bins, float)
614 bins = [xedges, yedges]
--> 615 hist, edges = histogramdd([x,y], bins, range, normed, weights)
616 return hist, edges[0], edges[1]
617
C:\Python27\ArcGISx6410.2\lib\site-packages\numpy\lib\function_base.pyc in histogramdd(sample, bins, range, normed, weights)
279 # Sample is a sequence of 1D arrays.
280 sample = atleast_2d(sample).T
--> 281 N, D = sample.shape
282
283 nbin = empty(D, int)
ValueError: too many values to unpack
내가 달성하기 위해 노력하고 무엇은 :
나는 두 배열을 가지고있다. 하나의 배열은 Landcover 클래스 (예 : 1 = Tree, 2 = Grass, 3 = Building 등)를 나타내는 지리 데이터 집합 (래스터)에서 가져옵니다. 다른 배열은 일종의 정치적 경계 (예 : 소포, 센서스 블록, 도시 등)를 나타내는 지리 데이터 집합 (래스터)에서 가져옵니다. 각 고유 한 정치적 경계 영역 (배열 값은 고유 한 ID를 나타냄)을 행으로 표시하고 각 토지 덮개 클래스의 각 경계 내 총 픽셀 수를 열로 표시하는 표를 얻으려고합니다.
감사합니다. 유망 해 보입니다. 얼마나 많은 영역이나 값의 픽셀이 많은지 얼마나 잘 수행 할 수 있는지 알고 있습니까? 예를 들어, 단일 영역에 수천 개의 셀이 포함되어있는 것은 전례가 없습니다. – Brian
충분히 빠르지 만, 이것은 numpy가 만들어지는 것입니다. 그러나 알 수있는 유일한 방법은 그것을 테스트하는 것입니다. 존이 순차적이면,'np.histogram2d'를 사용하는 것이 더 빠르지 만, 그렇지 않다면'np.unique (존)의 존'에 대한리스트 이해를해야 할 것입니다. – askewchan