[Numpy-discussion] Matlab Translation - sqrt elementwise
Travis Oliphant
oliphant.travis@ieee....
Tue Apr 17 14:09:14 CDT 2007
Miquel Poch wrote:
> Hi,
>
> I've found the next expression write it in Matlab,
>
> Rtx = sqrt(Rt);
>
> Rtx is a matrix, and that's why I need sqrt() to operate elementwise.
> I've read NumPy tutorial, and I know it's possible,
>
> A set of this functions, has been provided wich optimize certain kinds
> of calculations on arrays. Most of this functions, such as sin, cos
> and sqrt are unary functions wich operate elementwise. [Numerical
> Python, pg. 13]
>
> but I don't know who to do it. The next error appear when I execute
> the code,
>
> ''' exceptions.TypeError : only length-1 arrays can be converted to
> Python scalars ''
It is a good idea to always show the code that leads to the error.
Otherwise, we are guessing as to what you are really doing.
In this case, you are probably using the sqrt function from the math
module rather than the sqrt function from the numpy module.
Try:
import numpy
numpy.sqrt(Rt)
-Travis
More information about the Numpy-discussion
mailing list