Search code examples
pythonnumpy

root mean square in numpy and complications of matrix and arrays of numpy


Can anyone direct me to the section of numpy manual where i can get functions to accomplish root mean square calculations ... (i know this can be accomplished using np.mean and np.abs .. isn't there a built in ..if no why?? .. just curious ..no offense)

can anyone explain the complications of matrix and arrays (just in the following case):

U is a matrix(T-by-N,or u say T cross N) , Ue is another matrix(T-by-N) I define k as a numpy array

U[ind,:] is still matrix

in the following fashion k = np.array(U[ind,:])

when I print k or type k in ipython

it displays following

K = array ([[2,.3 .....
              ......
                9]])

You see the double square brackets (which makes it multi-dim i guess) which gives it the shape = (1,N)

but I can't assign it to array defined in this way

l = np.zeros(N)
shape = (,N) or perhaps (N,) something like that

l[:] = k[:]
error:
matrix dimensions incompatible

Is there a way to accomplish the vector assignment which I intend to do ... Please don't tell me do this l = k (that defeats the purpose ... I get different errors in program .. I know the reasons ..If you need I may attach the piece of code)

writing a loop is the dumb way .. which I'm using for the time being ...

I hope I was able to explain .. the problems I'm facing ..

regards ...


Solution

  • Try this:

    U = np.zeros((N,N))
    ind = 1
    k = np.zeros(N)
    k[:] = U[ind,:]