NumPy
NumPy is an extremely fast, multidimensional Python array processor designed specifically for Python and scientific computing but written in C. It is available via PyPI and installs easily. In addition to its amazing speed, the magic of NumPy includes its interaction with other libraries. NumPy can exchange data with GDAL, Shapely, the Python Imaging Library (PIL), and many other scientific computing Python libraries in other fields.
As a quick example of NumPy's ability, we'll combine it with GDAL to read in our sample satellite image and create a histogram of it. The interface between GDAL and NumPy is a GDAL module called gdalnumeric
which has NumPy as a dependency. Numeric is the legacy name of the NumPy module. The gdalnumeric
module imports NumPy.
In this example, we'll use gdalnumeric
, which imports NumPy, to read the image in as an array, grab the first band, and save it back out as a JPEG image:
>>> from osgeo import gdalnumeric >>> srcArray = gdalnumeric.LoadFile...