How can I make this piece of code even faster?

Serhiy Storchaka storchaka at gmail.com
Sun Jul 21 09:11:27 CEST 2013


20.07.13 23:22, pablobarhamalzas at gmail.com написав(ла):
>          e = math.e
>
>          count = -1
>          for x in range(hidden_num):
>              temp = 0
>              for y in range(input_num):
>                  count += 1
>                  temp += inputs[y] * h_weight[count]
>              hidden[x] = 1/(1+e**(-temp))
[...]
> My question to you is if you an see any obvious (or not so obvious) way of making this faster.

1. Use math.exp() instead of math.e**.

2. I'm not sure that it will be faster, but try to use sum().

   temp = sum(inputs[y] * h_weight[count + y] for y in range(input_num))
   count += input_num

or

   temp = sum(map(operator.mul, inputs, h_weight[count:count+input_num]))
   count += input_num





More information about the Python-list mailing list