I'm new to numpy but not python. Have a question about the
def _my_function(weights, features, bias):
# the pure python way
value = 0.
for i in range(len(weights)):
value += (weights[i]*features[i])
Approach #1: Using dot-product with np.dot -
weights.dot(features) + bias*len(weights)
Approach #2: Bringing in np.einsum to perform the sum-reduction -
np.einsum('i,i->',weights,features) + bias*len(weights)
I would think approach #1 would be the better one.