<p dir="ltr"><br>
</p>
<p dir="ltr"></p>
<p dir="ltr">On Fri, 30 Jan 2015 10:59 Moritz Lennert <<a href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonline.be</a>> wrote:</p>
<blockquote><p dir="ltr">On 29/01/15 18:30, Paulo van Breugel wrote:<br>
> I would like to compute a raster layer with for each raster cell the<br>
> mahalanobis distance to the centre of the environmental space// formed<br>
> by all reference data points (raster cells). In R this can be done as<br>
> explained here [1].<br>
><br>
> . I would like to do this using python only (no dependency on R). I came<br>
> up with the following, which works, but is very slow. I guess this is<br>
> because it loops over every raster cell to compute the mahalanobis<br>
> distance? Any idea how this can be done faster (I am very new to python,<br>
> so bear with me if I am making stupid mistakes)</p>
<p dir="ltr">There's probably ways to accelerate this in Python (maybe you can try<br>
rewriting your for-loops as map() calls), but on the Wikipedia page on<br>
mahalanobis distance that you reference [1], it says that:</p>
<p dir="ltr">"Along each principal component axis, it measures the number of standard<br>
deviations from P to the mean of D. If each of these axes is rescaled to<br>
have unit variance, then Mahalanobis distance corresponds to standard<br>
Euclidean distance in the transformed space."</p>
<p dir="ltr">Couldn't you use i.pca to calculate principal components and then<br>
calculate distances of points in that space ?</p>
<p dir="ltr">Just brainstorming...</p>
</blockquote>
<p dir="ltr"></p>
<p dir="ltr">Interesting thought. I will see if I can work that one out. Thanks!</p>
<blockquote><p dir="ltr"><br></p>
<p dir="ltr">Moritz<br></p>
<p dir="ltr">[1] <a href="http://en.wikipedia.org/wiki/Mahalanobis_distance">http://</a><a href="http://en.wikipedia.org/wiki/Mahalanobis_distance">en.wikipedia.org</a><a href="http://en.wikipedia.org/wiki/Mahalanobis_distance">/wiki/</a><a href="http://en.wikipedia.org/wiki/Mahalanobis_distance">Mahalanobis</a><a href="http://en.wikipedia.org/wiki/Mahalanobis_distance">_distance</a><br>
</p>
</blockquote>
<p dir="ltr"><br>
</p>