Hướng dẫn list comprehension python multiplication
The Show Nội dung chính
Python 3.x
Of course:
is equivalent to
So we can get our solution via:
In Python 2.x Instead of Python 2.7
Python 3.5+
Please note that since
Created: February-02, 2021 | Updated: February-07, 2021
This tutorial will demonstrate various methods to perform element-wise multiplication of two lists in Python. Suppose we have two lists of integers with the same dimensions and we want to multiply elements of the first list with the elements at the same position in the second list and get a resultant list with the same dimensions. Multiply Two List in Python Using the zip() MethodThe built-in The below code example shows how to multiple 1D and 2D lists using
Output:
Multiplication of 2D Lists:
Output:
Multiply Two Lists in Python Using the numpy.multiply() MethodThe The below code examples demonstrates how to multiply 1D and 2D lists in Python using the
Output:
Output:
Multiply Two Lists in Python Using the map() FunctionThe We can perform 1D and 2D element-wise multiplication of two lists in Python using the Example code for 1D multiplication:
Output:
Example code for 2D multiplication:
Output:
Write for us DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page. Related Article - Python List |