python - Numpy Element-wise Standard Deviation -


say have n 2-dimensional matricies m1, m2, m3, ... same dimensions.

is there efficient way produce output matrix mr each element in mr corresponds standard deviation of elements in position in m1, m2, m3, ...

an example of operation follows:

       1 4 5   8 2 3   -1 8 2      4.73  3.06  1.53 stdev( 3 9 2,  2 1 0,   0 3 1 ) =  1.53  4.16  1.00        7 1 2   8 3 1    9 5 8      1.00  2.00  3.79 

to clarify: top left element of resultant matrix calculated follows:

stdev(1,8,-1) = 4.7258 

whereas bottom left element calculated as:

stdev(7,8,9) = 1.00 

if not way built-in operators in 1 go there efficient alternative?

here test matrices:

a=numpy.array( [[1,4,5],[3,9,2],[7,1,2]]) b=numpy.array( [[8,2,3],[2,1,0],[8,3,1]]) c=numpy.array([[-1,8,2],[0,3,1],[9,5,8]]) 

numpy friend

import numpy np print np.std((a,b,c), axis=0, ddof=1) 

for provided matrices gives

array([[ 4.72581563,  3.05505046,  1.52752523],        [ 1.52752523,  4.163332  ,  1.        ],        [ 1.        ,  2.        ,  3.7859389 ]]) 

as expected


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -