python - Correlate one set of vectors to another in numpy? -


Suppose I have a set of vectors (reading from sensor 1, reading from sensor 2, reading from sensor 3 - indexed) before timestamp and then by sensor id) that i have a different set of vectors (temperature, humidity, etc.) - Everyone is indexed by TitelStamp and want to correlate with the other kind).

Is this the safest way to do numpy? It seems that this should be a simple task ...

In other words, I want to see:

  & gt; A.shape (365,20) & gt; B Size (365, 5) & gt; Correlations = magic_correlation_function (a, b) & gt; Co - relationship. Size (20, 5)  

Cheers, / YGA

p. s. I have been asked to add an example.

Here's what I would like to see:

  $ in [27]: x $ out [27]: array ([[0, 0, 0], [-1] , 0, -1], [-2, 0, -2], [-3, 0, -3], [-4, 0.1, -4]] in $ [28]: y $ out [28] In the $ [28]: magical_correlation_function (x, y) $ out [= 0, 0], [1, 0], [2, 0], [3, 0], [4, 0.1]] $ out [ 28]: Array ([[-1, 0.70710678, 1] [-0.70710678, 1., 0.70710678]]  

Ps2: Whoops, misrepresentation of my example Sorry all. Now fixed.

The simplest thing that I could find was using the scipy.stats package

-2], [-3, 0., -3], [-4., 0.1, -4.]]) In [9]: Y ou [9]: array ([[0 [0], [ 1., 0.], [2., 0.], [3., 0.], [4., 0.1]]) [10]: import scipy.stats [27]: (Scipy.stats.cov (X, ax = 0) )) Out [27]: Array ([[1, 0.70710678, -1], [-0.70710678, 1., -0.70710678]])

These numbers are not available to you, But you've merged your rows (element [0,0] 1

A more complex, but purely lower solution

 in  [40]: numpy.corrcoef (xT, yt) [Numpy.arange (x .shape [1]) [numpy.newaxis,:], numpy.arange (y.shape [1]) [:, numpy.newaxis]] out [40]: array ([- - 1., 0.70710678, -1 ], [-0.70710678, 1., -0.70710678]]  

This will be slow as it connects the correlation of each element in X to the element in X, which you Also, advanced indexing techniques that you want to get the subsets of the array are the ones you want. And may hurt.

If you are going numerically numeric, then get familiar with the rules and they will help push you as much as possible to the level of the level.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -