Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3213442
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:56:42+00:00 2026-05-17T14:56:42+00:00

Trying to imitate Excel’s SUMPRODUCT function: SUMPRODUCT(v1, v2, …, vN) = v1[0]*v2[0]*…*vN[0] + v1[1]*v2[1]*…*vN[1]

  • 0

Trying to imitate Excel’s SUMPRODUCT function:

SUMPRODUCT(v1, v2, ..., vN) =
    v1[0]*v2[0]*...*vN[0] + v1[1]*v2[1]*...*vN[1] + ... + v1[n]*v2[n]*...*vN[n]

where n is the number of elements in each vector.

This is similar to dot product, but for multiple vectors. I read the very detailed discussion of the regular dot product, but I don’t know how to cleanly extend it to multiple vectors. For reference, I’m copying the optimized code proposed there, which I ported (trivially) to Python 3. BTW, for dot product, the last approach still wins in P3K.

def d0(v1,v2):
    """                                                                                                     
    d0 is Nominal approach:                                                                                 
    multiply/add in a loop                                                                                  
    """
    out = 0
    for k in range(len(v1)):
        out += v1[k] * v2[k]
    return out

def d1(v1,v2):
    """                                                                                                     
    d1 uses a map                                                                        
    """
    return sum(map(mul,v1,v2))

def d3(v1,v2):
    """                                                                                                     
    d3 uses a starmap (itertools) to apply the mul operator on an zipped (v1,v2)                           
    """
    return sum(starmap(mul,zip(v1,v2)))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:56:43+00:00Added an answer on May 17, 2026 at 2:56 pm
    import operator
    
    def sumproduct(*lists):
        return sum(reduce(operator.mul, data) for data in zip(*lists))
    

    for python 3

    import operator
    import functools
    
    def sumproduct(*lists):
        return sum(functools.reduce(operator.mul, data) for data in zip(*lists))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to imitate this tutorial about creating a simple Apple-themed breadcrumb found
I am trying to imitate the sliding effect of this website: http://www.mckinsey.com/ I went
Basically what I am trying to do is to imitate the replace button with
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text
So this is sort of a question about a posted solution. I was trying
I'm trying to program two buttons to imitate the up/down arrow key behavior, meaning
i am trying to imitate the sample given with using autofac, but constantly getting
I'm trying to subclass a NSCollectionView which imitate the behaviors of UITableView as Twitter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.