Cara menggunakan multiply in python

The Operator takes the RapidMiner Object from the input port and delivers copies of it to the output ports. Each connected port creates an independent copy. So changing one copy has no effect on other copies.

Differentiation

Many Operators have an output port named original or throughput, which does not change the input. By chaining Operators to one or more original ports also copies of an object can be created. But such a layout can get complicated very fast. The Multiply Operator helps to better structure a RapidMiner Process.

Input

  • Cara menggunakan multiply in python
    input
    (IOObject)

    The input that should be copied. It can be any RapidMiner Object.

Output

  • Cara menggunakan multiply in python
    output
    (IOObject)

    The copy of the input object. As one output port is connected, another output port is created for more copies. All ports deliver unchanged copies of the input object.

Tutorial Processes

Multiply an ExampleSet

In this tutorial Process the Multiply Operator creates two copies of the Titanic Example Set. All missing values of the first copy are replaced by the average value and then 100 random Examples are selected. The second copy is not modified. This illustrates that the copies are independent and changes on one copy are not applied on the other copies.

Initialize the value of the product to 1(not 0 as 0 multiplied with anything returns zero). Traverse till the end of the list, multiply every number with the product. The value stored in the product at the end will give you your final answer.

Below is the Python implementation of the above approach:  

Python




# Python program to multiply all values in the

Input : list1 = [3, 2, 4] 
Output : 24 
0

 

 

Input : list1 = [3, 2, 4] 
Output : 24 
1
Input : list1 = [3, 2, 4] 
Output : 24 
2

 

Input : list1 = [3, 2, 4] 
Output : 24 
3
Input : list1 = [3, 2, 4] 
Output : 24 
4

Input : list1 = [3, 2, 4] 
Output : 24 
3
Input : list1 = [3, 2, 4] 
Output : 24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

Input : list1 = [3, 2, 4] 
Output : 24 
3
6
24
0
6
24
1
6
24
2
6
24
3

6
24
4
Input : list1 = [3, 2, 4] 
Output : 24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
6
6
24
8
6
24
1

Input : list1 = [3, 2, 4] 
Output : 24 
3
6
24 
1
Input : list1 = [3, 2, 4] 
Output : 24 
6

 

 

6
24 
3

6
24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8
6
24 
8
6
24 
9
6
24 
8
6
24
1
6
24
2

6
24
3
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
6
24
1
6
24 
8
6
24 
9
6
24 
8
6
24 
0
6
24
2

6
24 
2
6
24 
3

6
24 
2
6
24 
5

Output

6
24

Method 2: Using numpy.prod()

We can use numpy.prod() from import numpy to get the multiplication of all the numbers in the list. It returns an integer or a float value depending on the multiplication result.

Below is the Python3 implementation of the above approach:  

Python3




6
24 
6

6
24 
7

 

6
24 
8
6
24 
9

6
24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8
6
24 
8
6
24 
9
6
24 
8
6
24
1
6
24
2

6
24
3
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
6
24
1
6
24 
8
6
24 
9
6
24 
8
6
24 
0
6
24
2

 

6
24
8

6
24
9
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24
1

6
24
2
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24
4

6
24 
2
6
24
6

6
24 
2
6
24
8

Output: 
 

6
24 

Method 3 Using lambda function: Using numpy.array

Lambda’s definition does not include a “return” statement, it always contains an expression that is returned. We can also put a lambda definition anywhere a function is expected, and we don’t have to assign it to a variable at all. This is the simplicity of lambda functions. The reduce() function in Python takes in a function and a list as an argument. The function is called with a lambda function and a list and a new reduced result is returned. This performs a repetitive operation over the pairs of the list.

Below is the Python3 implementation of the above approach:  

Python3




6
24 
6

# Python program to multiply all values in the0

 

# Python program to multiply all values in the1 # Python program to multiply all values in the2

6
24 
8 # Python program to multiply all values in the4

6
24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8
6
24 
8
6
24 
9
6
24 
8
6
24
1
6
24
2

6
24
3
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
6
24
1
6
24 
8
6
24 
9
6
24 
8
6
24 
0
6
24
2

 

 

6
24
9
Input : list1 = [3, 2, 4] 
Output : 24 
7 # Python program to multiply all values in the4
Input : list1 = [3, 2, 4] 
Output : 24 
16
Input : list1 = [3, 2, 4] 
Output : 24 
17
Input : list1 = [3, 2, 4] 
Output : 24 
18
6
24
8
Input : list1 = [3, 2, 4] 
Output : 24 
20

6
24
2
Input : list1 = [3, 2, 4] 
Output : 24 
7 # Python program to multiply all values in the4
Input : list1 = [3, 2, 4] 
Output : 24 
16
Input : list1 = [3, 2, 4] 
Output : 24 
17
Input : list1 = [3, 2, 4] 
Output : 24 
18
6
24
8
Input : list1 = [3, 2, 4] 
Output : 24 
28

6
24 
2
6
24
6

6
24 
2
6
24
8

Output

6
24

Method 4 Using prod function of math library: Using math.prod

Starting Python 3.8, a prod function has been included in the math module in the standard library, thus no need to install external libraries.

Below is the Python3 implementation of the above approach:  

Python3




6
24 
6

Input : list1 = [3, 2, 4] 
Output : 24 
34

 

6
24 
8
Input : list1 = [3, 2, 4] 
Output : 24 
36

6
24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8
6
24 
8
6
24 
9
6
24 
8
6
24
1
6
24
2

6
24
3
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
6
24
1
6
24 
8
6
24 
9
6
24 
8
6
24 
0
6
24
2

 

 

6
24
9
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
57

6
24
2
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
60

6
24 
2
6
24
6

6
24 
2
6
24
8

Output: 
 

6
24 

Method 5: Using mul() function of operator module. 

First we have to import the operator module then using the mul() function of operator module multiplying the all values in the list. 

Python3




Input : list1 = [3, 2, 4] 
Output : 24 
65

Input : list1 = [3, 2, 4] 
Output : 24 
66

 

# Python program to multiply all values in the1

Input : list1 = [3, 2, 4] 
Output : 24 
68
6
24 
8
6
24
8

6
24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8
6
24 
8
6
24 
9
6
24 
8
6
24
1
6
24
2

Input : list1 = [3, 2, 4] 
Output : 24 
80
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

6
24
0
Input : list1 = [3, 2, 4] 
Output : 24 
84
6
24
2
Input : list1 = [3, 2, 4] 
Output : 24 
86

Input : list1 = [3, 2, 4] 
Output : 24 
87
Input : list1 = [3, 2, 4] 
Output : 24 
88

Input : list1 = [3, 2, 4] 
Output : 24 
87
Input : list1 = [3, 2, 4] 
Output : 24 
90

Input : list1 = [3, 2, 4] 
Output : 24 
3
Input : list1 = [3, 2, 4] 
Output : 24 
80
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
94

Input : list1 = [3, 2, 4] 
Output : 24 
95

6
24 
2
Input : list1 = [3, 2, 4] 
Output : 24 
97

Output

6

Method 6: Using traversal by index

Python3




# Python program to multiply all values in the

Input : list1 = [3, 2, 4] 
Output : 24 
0

 

Input : list1 = [3, 2, 4] 
Output : 24 
1
6
24
01

Input : list1 = [3, 2, 4] 
Output : 24 

Input : list1 = [3, 2, 4] 
Output : 24 
3
Input : list1 = [3, 2, 4] 
Output : 24 
4

Input : list1 = [3, 2, 4] 
Output : 24 
3
Input : list1 = [3, 2, 4] 
Output : 24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

Input : list1 = [3, 2, 4] 
Output : 24 
3
6
24
0
Input : list1 = [3, 2, 4] 
Output : 24 
84
6
24
2
6
24
13
6
24
14
6
24
15
6
24 
8
6
24
17
6
24
18