I have a matrix
import numpy as np
A = np.array([[.7,.2,.1],[0,.6,.4],[.5,0,.5]]);A
I want to make a function that calculate a stationarity :
def statdist(A):
m = A.shape[0]
s = (m,m)
I = np.identity(3)
return( np.ones(m)@np.linalg.inv(I)- A+np.ones(s))
statdist(A)
The result must be
0.4761905 0.2380952 0.2857143
but the output from python is a matrix:
array([[1.3, 1.8, 1.9],
[2. , 1.4, 1.6],
[1.5, 2. , 1.5]])
What I make wrong ?
In R is simple right :
statdist <- function(gamma){
m = dim(gamma)[1]
matrix(1,1,m) %*% solve(diag(1,m) - gamma + matrix(1,m,m))
}
i = matrix(c(.7,.2,.1,0,.6,.4,.5,0,.5),3,3,byrow = TRUE);i
statdist(i)
(3,), while the second one- A+np.ones(s)is a sum of two 3x3 matrices.np.ones(m)@np.linalg.inv(I- A+np.ones(s))np.ones(m).reshape((1,m)is (3,1) but still the result is wrong