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

  • Home
  • SEARCH
  • 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 4075538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:18:40+00:00 2026-05-20T17:18:40+00:00

I have a one dimensional NumPy array: a = numpy.array([2,3,3]) I would like to

  • 0

I have a one dimensional NumPy array:

a = numpy.array([2,3,3])

I would like to have the product of all elements, 18 in this case.

The only way I could find to do this would be:

b = reduce(lambda x,y: x*y, a)

Which looks pretty, but is not very fast (I need to do this a lot).

Is there a numpy method that does this? If not, what is the most efficient way of doing this? My real world arrays have 39 float elements.

  • 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-20T17:18:41+00:00Added an answer on May 20, 2026 at 5:18 pm

    In NumPy you can try:

    numpy.prod(a)
    

    For a larger array numpy.arange(1,40) / 10.:

    array([ 0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ,  1.1,
            1.2,  1.3,  1.4,  1.5,  1.6,  1.7,  1.8,  1.9,  2. ,  2.1,  2.2,
            2.3,  2.4,  2.5,  2.6,  2.7,  2.8,  2.9,  3. ,  3.1,  3.2,  3.3,
            3.4,  3.5,  3.6,  3.7,  3.8,  3.9])
    

    your reduce(lambda x,y: x*y, a) needs 24.2µs,

    numpy.prod(a) needs 3.9µs.

    EDIT: a.prod() needs 2.67µs. Thanks to J.F. Sebastian!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one-dimensional array of strings in JavaScript that I'd like to turn
I have two identically-sized numpy.array objects (both one-dimensional), one of which contains a list
I have this PHP one dimensional array: Array ( [Female--N] => 11 [Male--N] =>
I have a two dimensional list and a one dimensional list. I would like
In C++ you can easily allocate one dimensional array like this: T *array=new T[N];
I have a function that take a one dimensional array and returns all the
I have a program which needs to turn many large one-dimensional numpy arrays of
Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to
I have an array of documents, where each document have another simple one-dimensional array
I have one hibernate sequence, that generates all sequence-numbers in my app. When I

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.