[SciPy-User] numpy array root operation
Oleksandr Huziy
guziy.sasha@gmail....
Wed Mar 21 22:22:46 CDT 2012
Maybe like this,
>>> import numpy as np
>>> x = np.array([-81,25])
>>> np.sign(x) * np.absolute(x) ** (1.0/5.0)
array([-2.40822469, 1.90365394])
>>> np.sign(x) * np.absolute(x) ** (1.0/2.0)
array([-9., 5.])
try this way and you'll be also in trouble
(-32)**(1.0/5.0)
Cheers
--
Oleksandr Huziy
2012/3/21 Odin Den <hate_pod@yahoo.com>:
> Hi,
> 5th root of -32 can be computed correctly as follows:
>>>> -32**(1/5)
>>>> -2.0
>
> However, when I try to perform same operation on numpy arrays I get
> the following:
>>>> array([-32])**(1/5)
>>>> array([ nan])
>
> Is there anyway to compute roots of numpy arrays? I have a huge matrix which
> contains both negative and positive values. What is the easiest way of making
> python compute the "nth" roots of each element of this matrix without knowing
> the value of "n" a priory?
>
>
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list