Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #K-mean cluster of Gandhinagar SRTM 30m DEM Using SCIPY Lib
- import scipy as sp
- #reading rasterdata into array form "osgeo"
- from osgeo import gdal
- #plot graph
- from pylab import plot,show
- import numpy as np
- from scipy.cluster.vq import kmeans,vq
- dem=gdal.Open(r"C:\Users\lenovo\Desktop\scipy\SRTM-30.tif")
- features = np.array(dem.GetRasterBand(1).ReadAsArray(),dtype=float)
- print (features.shape)
- print (features)
- # computing K-Means with K = 2 (2 clusters)
- codes = 2
- # assign each sample to a cluster
- centroids,_ = kmeans(features,codes)
- #centroids will show me the important pattern of data
- #vq= vector quantization
- #vq vector quantaization =Assign codes from a code book to observations.
- idx,_ = vq(features,centroids)
- # some plotting using numpy's logical indexing
- plot(features[idx==0,0],features[idx==0,1],'ob',
- features[idx==1,0],features[idx==1,1],'or')
- plot(centroids[:,0],centroids[:,1],'sg',markersize=8)
- show()
Add Comment
Please, Sign In to add comment