We have addressed the seismic impedance inversion problem, which is often ill posed because of inaccurate and insufficient data. The approach taken is based on dictionary learning and sparse representation. By shifting a patch window of fixed size on all well-log data, a large number of small overlapping patches are generated. Then regarding these patches as a training set and using K-singular value decomposition algorithm, we obtain a dictionary that describes the common features of subsurface models within the current survey area. On the basis of the assumption that the subsurface geology has similarity and lateral continuity to some extent, the dictionary is used to approximate each model via sparse representations over the learned dictionary. In particular, we impose the sparse representations as additional constraints into the inversion procedure, leading to a well-defined objective function that can not only fit the observed seismic data but also honor the features of the well-log data. We adopt a coordinate descent strategy to solve this objective function. Meanwhile, to enforce lateral continuity in the inverted models, we use an additional stage in which we use the nonlocal similarity information that is extracted from seismic data as spatial coherent prior knowledge to refine the estimated models. Compared with several traditional impedance inversion methods, our algorithm can produce solutions of much higher quality qualitatively and quantitatively.