Incrementing part of an array in numpy
given a (2D) array a, and a smaller (2D) array b, how can you add the smaller array to the bigger array at some offset in numpy? >>> a = zeros((4,4), dtype=int) >>> a array([[0, 0, 0, 0], [0, 0,…
given a (2D) array a, and a smaller (2D) array b, how can you add the smaller array to the bigger array at some offset in numpy? >>> a = zeros((4,4), dtype=int) >>> a array([[0, 0, 0, 0], [0, 0,…
Mostly so I myself can remember how to do it, here is how to create a random geotiff with GDAL in Python Note: the width and height are given in opposite order in the GDAL raster and numpy arrays! import…
This is a good post showing how “perrygeo” uses Cython to speed up a pure Python function. The comments also discuss alternatives and options: Using psyco instead of Cython Using optimization flags for gcc Using xxx instead of math.xxx
How long does [insert code snippet] take in Python? Find out with the timeit module, in Python since 2.3. Below I time how long it takes to make a list with a 1000 zeros, [0,0,0,…], using different Python code snippets.…
pyproj is a Python interface to the PROJ.4 () functions. It allows you to transform coordinates between coordinate systems. Install pyproj using pip Assuming you’re using pip to install Python packages: $ pip install pyproj
I tried the Tor browser today, and was amazed at how slow it was. As Tor’s user base has grown, the performance of the Tor network has suffered. This document describes the current understanding of why Tor is slow, and…
The recommended practice is to have different passwords on different websites. But how do you remember all those passwords without storing them somewhere? The tricks is, you don’t. You remember a single strong password, and use a mechanism to generate…
Note: Since writing this post, I’ve learned about the fileinput module, which turns most of the following into a oneliner: import fileinput for line in fileinput.input(): process(line)
In this post I’ll compare the running time of reading uncompressed and compressed files from disc. I’ll run a test using two files, data.txt (858M) and data.txt.gz (83M), that have the same content. About cat and zcat The well-known command…
Here is a map application that illustrates very well the different tile schemes used (TMS, QuadTree, Google Maps):