Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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 ...

like image 317
fedvasu Avatar asked Apr 10 '11 16:04

fedvasu


People also ask

How do you take the square root of a matrix in NumPy?

Python NumPy module is used to work with multidimensional arrays and matrix manipulations. We can use NumPy sqrt() function to get the square root of the matrix elements.

What is square root in NumPy?

The sqrt() function in NumPy computes the non-negative square root of each element of an input array.

What is the difference between NumPy array and NumPy matrix?

Numpy matrices are strictly 2-dimensional, while numpy arrays (ndarrays) are N-dimensional. Matrix objects are a subclass of ndarray, so they inherit all the attributes and methods of ndarrays.


1 Answers

For the RMS, I think this is the clearest:

from numpy import mean, sqrt, square, arange
a = arange(10) # For example
rms = sqrt(mean(square(a)))

The code reads like you say it: "root-mean-square".

like image 194
deprecated Avatar answered Oct 12 '22 21:10

deprecated