Some questions on pow and random

joy99 subhakolkata1234 at gmail.com
Sun Mar 27 12:02:00 EDT 2011


On Mar 27, 8:52 pm, Mark Dickinson <dicki... at gmail.com> wrote:
> On Mar 27, 3:00 pm, joy99 <subhakolkata1... at gmail.com> wrote:
>
> > (i) Suppose we have 8 which is 2^3 i.e., 3 is the power of 2, which we
> > are writing in Python as,
> > variable1=2
> > variable2=3
> > result=pow(variable1,variable2)
>
> > In my first problem p(x) a list of float/decimals and f(x) is another
> > such.
> > Here,
> > variable1=p(x)
> > variable2=f(x)
> > so that we can write, pow(variable1,variable2) but as it is a list not
> > a number and as the size is huge, so would it pow support it?
>
> No:  pow won't work on lists.  It will work on (a) numbers (pow(2, 3) -> 8),
>
> or (b) numpy arrays, e.g.:
>
> >>> import numpy as np
> >>> x = np.array([0.1, 0.5, 0.4])
> >>> y = np.array([3, 24, 18])
> >>> pow(x, y)
>
> array([  1.00000000e-03,   5.96046448e-08,   6.87194767e-08])>>> x ** y # exactly equivalent
>
> array([  1.00000000e-03,   5.96046448e-08,   6.87194767e-08])
>
> > (ii) The second question is, if I have another set of variables,
>
> > variable1=random.random()
> > variable2=random.random()
>
> In this case 'variable1' and 'variable2' are Python floats, so yes,
> you can multiply them directly.  (BTW, you can always experiment
> directly at the Python interactive prompt to answer this sort of
> question.)
>
> Mark

Thanks Mark. Wishing you a nice day ahead.
Best Regards,
Subhabrata.



More information about the Python-list mailing list