About 3,010,000 results
Open links in new tab
  1. python - How to perform element-wise multiplication of two

    Use np.multiply (a,b): The result is then an np.array [2 6 12 20], not a Python list [2, 6, 12, 20]. But you can write np.multiply (a,b).tolist () if you need a Python list. You can try multiplying each element in a loop. The short hand for doing that is.

  2. Python – Multiply Two Lists - GeeksforGeeks

    Jan 31, 2025 · List comprehension allows multiplying two lists element-wise by iterating over their indices and applying the multiplication directly. Python a = [ 1 , 2 , 3 ] b = [ 4 , 5 , 6 ] # Use list comprehension to multiply corresponding elements from both lists res = [ a [ i ] * b [ i ] for i in range ( len ( a ))] print ( res )

  3. python - How do I multiply lists together using a function?

    Sep 26, 2013 · >>> import numpy as np >>> list = [1,2,3,4] >>> np.multiply(list, list) array([ 1, 4, 9, 16]) If you prefer python lists: >>> np.multiply(list, list).tolist() [1, 4, 9, 16] additionally, this also works for element-wise multiplication with a scalar. >>> np.multiply(list, 2) array([2, 4, 6, 8])

  4. Python: Multiply Lists (6 Different Ways) - datagy

    Dec 12, 2021 · In this tutorial, you’ll learn how to use Python to multiply lists, including how to multiply list elements by a number and multiply lists with one another. By the end of this tutorial, you’ll have learned how to multiply each element by a number, including how to do this with for loops, list comprehensions and numpy array multiplication.

  5. Multiplying corresponding elements from 2 lists in Python

    Write a program which multiplies corresponding elements in these lists. Input: Your program should read lines from standard input. Each line contains two space-delimited lists.

  6. How to Multiply in Python? [With Examples] - Python Guides

    Aug 8, 2024 · In Python, you can multiply lists by a number, which results in the list being repeated that many times. However, to multiply the corresponding elements of two Python lists, you need to use a loop or a list comprehension. Let me show you an example to …

  7. Python List Multiplication: A Comprehensive Guide - CodeRivers

    Mar 26, 2025 · In Python, list multiplication involves multiplying a list by an integer. When you multiply a list by an integer n , Python creates a new list that contains n copies of the original list. This operation is denoted using the multiplication operator ( * ).

  8. List Multiplication in Python: A Comprehensive Guide

    Apr 11, 2025 · List multiplication is a useful operation that can simplify certain programming tasks. It provides a concise way to create a new list that contains multiple copies of an existing list. This blog post will explore the concept of list multiplication in Python, its usage methods, common practices, and best practices.

  9. Python Multiplication List: Concepts, Usage, and Best Practices

    Apr 14, 2025 · A multiplication list in Python is a new list created by repeating the elements of an existing list a specified number of times. The multiplication operator ( * ) is used to perform this operation. For example, if you have a list [1, 2] and you multiply it by 3, you get a new list [1, 2, 1, 2, 1, 2] where the original list [1, 2] is repeated ...

  10. How to Multiply Two Lists in Python

    Nov 29, 2023 · We can multiply two lists together using the multiplication operator (*). This will result in a new list that contains as many copies of the second list as there are items in the first one: In the above example, len(list2) is used to get the length of list2.

Refresh